Fix bug with zlibDecompressFilesRecursive
This commit is contained in:
@@ -62,6 +62,7 @@ function cli.parseArgs(): types.opts
|
||||
i = i + 1
|
||||
elseif arg == "--zlib-decompress-recursive" then
|
||||
opts.zlibDecompressFilesRecursive = true
|
||||
i = i + 1
|
||||
else
|
||||
if not opts.directoryMode then
|
||||
table.insert(opts.filesToProcess, arg)
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ end
|
||||
function core.fileContainsWorkspace(fileContents: string, opts: types.opts): boolean
|
||||
assert(typeof(fileContents) == "string", "Expected fileContents to be of type 'string'")
|
||||
assert(typeof(opts) == "table", "Expected opts to be of type 'table'")
|
||||
if opts.zlibDecompressFiles then
|
||||
if opts.zlibDecompressFiles or opts.zlibDecompressFilesRecursive then
|
||||
local success = pcall(function() fileContents = compression.zlibDecompress(fileContents, opts.zlibDecompressFilesRecursive) end)
|
||||
if not success then
|
||||
stdio.write(stdio.color("yellow"))
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
local fs = require("@lune/fs")
|
||||
local stdio = require("@lune/stdio")
|
||||
local process = require("@lune/process")
|
||||
local serde = require("@lune/serde")
|
||||
local core = require("./core")
|
||||
local types = require("./types")
|
||||
|
||||
export type FileProc = {
|
||||
collectFiles: (opts: types.opts) -> {string},
|
||||
processFiles: (filesToProcess: {string}, opts: types.opts) -> {string},
|
||||
zlibDecompress: (contents: string, recursive: boolean?) -> string | boolean
|
||||
}
|
||||
|
||||
local fileproc = {} :: FileProc
|
||||
@@ -90,25 +88,5 @@ function fileproc.processFiles(filesToProcess: {string}, opts: types.opts): {str
|
||||
return filesWithWorkspace
|
||||
end
|
||||
|
||||
-- take in file contents and zlib decompress them
|
||||
-- if recursive param is true repeatedly zlib decompress the file until it fails
|
||||
-- (modelscrape files are often double/triple zlib decompressed)
|
||||
function fileproc.zlibDecompress(contents: string, recursive: boolean?): string | boolean
|
||||
assert(typeof(contents) == "string", "Expected contents to be of type 'string'")
|
||||
if recursive == nil then recursive = false end
|
||||
assert(typeof(recursive) == "boolean", "Expected recursive to be of type 'boolean'")
|
||||
local success, decompressed = pcall(function() return serde.decompress("zlib", contents) end)
|
||||
if not success then
|
||||
return false
|
||||
end
|
||||
if recursive then
|
||||
local nextDecompressed = fileproc.zlibDecompress(decompressed, true)
|
||||
while nextDecompressed do
|
||||
decompressed = nextDecompressed
|
||||
nextDecompressed = fileproc.zlibDecompress(decompressed, true)
|
||||
end
|
||||
end
|
||||
return decompressed
|
||||
end
|
||||
|
||||
return fileproc
|
||||
|
||||
Reference in New Issue
Block a user