fix: entry metadata not including method

Also updates metadata tests to test for correct method detection.
This commit is contained in:
Erica Marigold 2025-01-07 18:53:45 +00:00
parent d5595135cd
commit 9b6216c0a7
Signed by: DevComp
GPG key ID: 429EF1C337871656
2 changed files with 12 additions and 6 deletions

View file

@ -232,7 +232,7 @@ function ZipReader.parseCentralDirectory(self: ZipReader): ()
ZipEntry.new(offset, name, {
size = size,
crc = crc,
compressionMethod = DECOMPRESSION_ROUTINES[compressionMethod].name,
method = DECOMPRESSION_ROUTINES[compressionMethod].name,
timestamp = timestamp,
attributes = externalAttrs,
isAscii = bit32.band(internalAttrs, 0x0001) ~= 0,

View file

@ -5,7 +5,7 @@ local DateTime = require("@lune/datetime")
local frktest = require("../lune_packages/frktest")
local check = frktest.assert.check
local ZipReader = require("../lib")
local unzip = require("../lib")
local ZIPS = fs.readDir("tests/data")
local FALLIBLES = {
@ -18,6 +18,11 @@ local FALLIBLES = {
"chinese.zip" -- FIXME: Support encoding other than UTF-8 and ASCII using OS APIs after FFI
}
local METHOD_NAME_TRANSFORMATIONS: { [string]: unzip.CompressionMethod } = {
["Defl:N"] = "DEFLATE",
["Stored"] = "STORE",
}
local function timestampToValues(dosTimestamp: number): DateTime.DateTimeValues
local time = bit32.band(dosTimestamp, 0xFFFF)
local date = bit32.band(bit32.rshift(dosTimestamp, 16), 0xFFFF)
@ -83,7 +88,7 @@ return function(test: typeof(frktest.test))
checkErr(function(...)
file = "tests/data/" .. file
local data = fs.readFile(file)
local zip = ZipReader.load(buffer.fromstring(data))
local zip = unzip.load(buffer.fromstring(data))
-- Get sizes from unzip command
local result = process.spawn("unzip", { "-v", file })
@ -99,8 +104,8 @@ return function(test: typeof(frktest.test))
and not string.match(line, "files?$")
and #line > 0
then
-- TODO: Expose information about method, size, and compression ratio in API
local length, _method, _size, _cmpr, expectedDate, expectedTime, crc32, name = string.match(
-- TODO: Expose information about size, and compression ratio in API
local length, method, _size, _cmpr, expectedDate, expectedTime, crc32, name = string.match(
line,
"^%s*(%d+)%s+(%S+)%s+(%d+)%s+([+-]?%d*%%?)%s+(%d%d%d%d%-%d%d%-%d%d)%s+(%d%d:%d%d)%s+(%x+)%s+(.+)$"
)
@ -110,8 +115,9 @@ return function(test: typeof(frktest.test))
local gotDateTime = DateTime.fromLocalTime(
timestampToValues(entry.timestamp) :: DateTime.DateTimeValueArguments
)
check.equal(tonumber(length), entry.size)
check.equal(METHOD_NAME_TRANSFORMATIONS[method :: string], entry.method)
check.is_true(dateFuzzyEq(gotDateTime:formatLocalTime("%Y-%m-%d"), expectedDate :: string, 1))
-- TODO: Use extra datetime field