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
-22
View File
@@ -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