Fix bug with zlibDecompressFilesRecursive

This commit is contained in:
2025-09-25 00:34:32 -04:00
parent 74321fa18a
commit d9837ecb72
3 changed files with 2 additions and 23 deletions
+1
View File
@@ -62,6 +62,7 @@ function cli.parseArgs(): types.opts
i = i + 1 i = i + 1
elseif arg == "--zlib-decompress-recursive" then elseif arg == "--zlib-decompress-recursive" then
opts.zlibDecompressFilesRecursive = true opts.zlibDecompressFilesRecursive = true
i = i + 1
else else
if not opts.directoryMode then if not opts.directoryMode then
table.insert(opts.filesToProcess, arg) table.insert(opts.filesToProcess, arg)
+1 -1
View File
@@ -39,7 +39,7 @@ end
function core.fileContainsWorkspace(fileContents: string, opts: types.opts): boolean function core.fileContainsWorkspace(fileContents: string, opts: types.opts): boolean
assert(typeof(fileContents) == "string", "Expected fileContents to be of type 'string'") assert(typeof(fileContents) == "string", "Expected fileContents to be of type 'string'")
assert(typeof(opts) == "table", "Expected opts to be of type 'table'") 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) local success = pcall(function() fileContents = compression.zlibDecompress(fileContents, opts.zlibDecompressFilesRecursive) end)
if not success then if not success then
stdio.write(stdio.color("yellow")) stdio.write(stdio.color("yellow"))
-22
View File
@@ -2,14 +2,12 @@
local fs = require("@lune/fs") local fs = require("@lune/fs")
local stdio = require("@lune/stdio") local stdio = require("@lune/stdio")
local process = require("@lune/process") local process = require("@lune/process")
local serde = require("@lune/serde")
local core = require("./core") local core = require("./core")
local types = require("./types") local types = require("./types")
export type FileProc = { export type FileProc = {
collectFiles: (opts: types.opts) -> {string}, collectFiles: (opts: types.opts) -> {string},
processFiles: (filesToProcess: {string}, opts: types.opts) -> {string}, processFiles: (filesToProcess: {string}, opts: types.opts) -> {string},
zlibDecompress: (contents: string, recursive: boolean?) -> string | boolean
} }
local fileproc = {} :: FileProc local fileproc = {} :: FileProc
@@ -90,25 +88,5 @@ function fileproc.processFiles(filesToProcess: {string}, opts: types.opts): {str
return filesWithWorkspace return filesWithWorkspace
end 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 return fileproc