mirror of
https://github.com/0x5eal/luau-unzip.git
synced 2025-04-04 06:30:53 +01:00
feat: rename extraction option field isString
->type
This commit is contained in:
parent
2d8d301481
commit
d88091ea5a
5 changed files with 13 additions and 14 deletions
|
@ -29,7 +29,7 @@ print("Directory structure:")
|
|||
reader:walk(function(entry, depth)
|
||||
local prefix = string.rep(" ", depth)
|
||||
local suffix = if not entry.isDirectory
|
||||
then string.format(" (%d bytes), content: %s", entry.size, reader:extract(entry, { isString = true }) :: string)
|
||||
then string.format(" (%d bytes), content: %s", entry.size, reader:extract(entry, { type = "text" }) :: string)
|
||||
else ""
|
||||
print(prefix .. entry.name .. suffix)
|
||||
end)
|
||||
|
|
|
@ -18,7 +18,7 @@ local function formatTree(tree: Tree): Tree<string>
|
|||
|
||||
-- File, format the value
|
||||
local fileEntry = value :: EntryData
|
||||
local content = reader:extract(assert(reader:findEntry(fileEntry.path)), { isString = true }) :: string
|
||||
local content = reader:extract(assert(reader:findEntry(fileEntry.path)), { type = "text" }) :: string
|
||||
local truncContents = content:gsub("\n", ""):sub(1, 100)
|
||||
|
||||
result[key] = string.format(
|
||||
|
@ -72,7 +72,7 @@ reader:walk(function(entry, depth)
|
|||
path = entry:getPath(),
|
||||
size = entry.size,
|
||||
attributes = entry.attributes,
|
||||
content = reader:extract(entry, { isString = true }) :: string,
|
||||
content = reader:extract(entry, { type = "text" }) :: string,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -59,8 +59,7 @@ type ZipEntryInner = {
|
|||
method: CompressionMethod, -- Method used to compress the file
|
||||
crc: number, -- CRC32 checksum of uncompressed data
|
||||
isDirectory: boolean, -- Whether the entry is a directory or not
|
||||
-- TODO: Rename to isText or similar in breaking change
|
||||
isAscii: boolean, -- Whether the entry is plain ASCII text or binary
|
||||
isText: boolean, -- Whether the entry is plain ASCII text or binary
|
||||
attributes: number, -- File attributes
|
||||
parent: ZipEntry?, -- The parent of the current entry, nil for root
|
||||
children: { ZipEntry }, -- The children of the entry
|
||||
|
@ -322,7 +321,7 @@ end
|
|||
type ExtractionOptions = {
|
||||
followSymlinks: boolean?,
|
||||
decompress: boolean?,
|
||||
isString: boolean?, -- TODO: Rename to isText or similar in breaking change
|
||||
type: ("binary" | "text")?,
|
||||
skipCrcValidation: boolean?,
|
||||
skipSizeValidation: boolean?,
|
||||
}
|
||||
|
@ -348,7 +347,7 @@ function ZipReader.extract(self: ZipReader, entry: ZipEntry, options: Extraction
|
|||
local defaultOptions: ExtractionOptions = {
|
||||
followSymlinks = false,
|
||||
decompress = true,
|
||||
isString = entry.isAscii,
|
||||
type = if entry.isText then "text" else "binary",
|
||||
skipValidation = false,
|
||||
}
|
||||
|
||||
|
@ -356,7 +355,7 @@ function ZipReader.extract(self: ZipReader, entry: ZipEntry, options: Extraction
|
|||
local optionsOrDefault: {
|
||||
followSymlinks: boolean,
|
||||
decompress: boolean,
|
||||
isString: boolean,
|
||||
type: "binary" | "text",
|
||||
skipCrcValidation: boolean,
|
||||
skipSizeValidation: boolean,
|
||||
} = if options
|
||||
|
@ -444,7 +443,7 @@ function ZipReader.extract(self: ZipReader, entry: ZipEntry, options: Extraction
|
|||
end
|
||||
|
||||
optionsOrDefault.followSymlinks = false
|
||||
optionsOrDefault.isString = false
|
||||
optionsOrDefault.type = "binary"
|
||||
optionsOrDefault.skipCrcValidation = true
|
||||
optionsOrDefault.skipSizeValidation = true
|
||||
content =
|
||||
|
@ -463,7 +462,7 @@ function ZipReader.extract(self: ZipReader, entry: ZipEntry, options: Extraction
|
|||
)
|
||||
end
|
||||
|
||||
return if optionsOrDefault.isString then buffer.tostring(content) else content
|
||||
return if optionsOrDefault.type == "text" then buffer.tostring(content) else content
|
||||
end
|
||||
|
||||
function ZipReader.extractDirectory(
|
||||
|
|
|
@ -32,10 +32,10 @@ return function(test: typeof(frktest.test))
|
|||
local entry = assert(zip:findEntry("/pandoc-3.2-arm64/bin/pandoc-lua"))
|
||||
assert(entry:isSymlink(), "Entry type must be a symlink")
|
||||
|
||||
local targetPath = zip:extract(entry, { isString = true }) :: string
|
||||
local targetPath = zip:extract(entry, { type = "text" }) :: string
|
||||
check.equal(targetPath, "pandoc")
|
||||
|
||||
local bin = zip:extract(entry, { isString = false, followSymlinks = true }) :: buffer
|
||||
local bin = zip:extract(entry, { type = "text", followSymlinks = true }) :: buffer
|
||||
local expectedBin =
|
||||
process.spawn("unzip", { "-p", "tests/data/pandoc_soft_links.zip", "pandoc-3.2-arm64/bin/pandoc" })
|
||||
check.is_true(expectedBin.ok)
|
||||
|
|
|
@ -37,8 +37,8 @@ return function(test: typeof(frktest.test))
|
|||
local zip = ZipReader.load(buffer.fromstring(data))
|
||||
|
||||
-- Test both string and buffer extraction
|
||||
local stringOptions = { isString = true, decompress = true }
|
||||
local bufferOptions = { isString = false, decompress = true }
|
||||
local stringOptions = { type = "text" :: "text", decompress = true }
|
||||
local bufferOptions = { type = "binary" :: "binary", decompress = true }
|
||||
|
||||
-- Extract and verify each file
|
||||
zip:walk(function(entry)
|
||||
|
|
Loading…
Add table
Reference in a new issue