diff --git a/lib/init.luau b/lib/init.luau index 72be767..80ee53e 100644 --- a/lib/init.luau +++ b/lib/init.luau @@ -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, diff --git a/tests/metadata.luau b/tests/metadata.luau index b7002a9..e37a3da 100644 --- a/tests/metadata.luau +++ b/tests/metadata.luau @@ -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