begin integration of recursive zlib compression.

This commit is contained in:
2025-09-24 14:21:06 -04:00
parent a79ad11f23
commit 68b4849504
5 changed files with 56 additions and 4 deletions
+16 -2
View File
@@ -2,7 +2,7 @@
local fs = require("@lune/fs")
local stdio = require("@lune/stdio")
local process = require("@lune/process")
local _serde = require("@lune/serde")
local serde = require("@lune/serde")
local core = require("./core")
local types = require("./types")
@@ -92,7 +92,21 @@ end
-- 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
error("fileproc.zlibDecompress is not implemented.")
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