mirror of
https://github.com/0x5eal/luau-unzip.git
synced 2025-04-18 12:43:45 +01:00
style: apply stylua formatter
This commit is contained in:
parent
792682e46d
commit
c2e638cbec
6 changed files with 911 additions and 774 deletions
|
@ -6,30 +6,31 @@ local reader = zip.load(buffer.fromstring(file))
|
||||||
|
|
||||||
print("Directory structure:")
|
print("Directory structure:")
|
||||||
reader:walk(function(entry, depth)
|
reader:walk(function(entry, depth)
|
||||||
local prefix = string.rep(" ", depth)
|
local prefix = string.rep(" ", depth)
|
||||||
local suffix = if not entry.isDirectory then string.format(" (%d bytes)", entry.size) else ""
|
local suffix = if not entry.isDirectory then string.format(" (%d bytes)", entry.size) else ""
|
||||||
print(prefix .. entry.name .. suffix)
|
print(prefix .. entry.name .. suffix)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
print("\nContents of `/`:")
|
print("\nContents of `/`:")
|
||||||
local assets = reader:listDirectory("/")
|
local assets = reader:listDirectory("/")
|
||||||
for _, entry in assets do
|
for _, entry in assets do
|
||||||
print(entry.name, if entry.isDirectory then "DIR" else entry.size)
|
print(entry.name, if entry.isDirectory then "DIR" else entry.size)
|
||||||
if not entry.isDirectory then
|
if not entry.isDirectory then
|
||||||
local extracted = reader:extract(entry, { isString = true })
|
local extracted = reader:extract(entry, { isString = true })
|
||||||
print("Content:", extracted)
|
print("Content:", extracted)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get archive statistics
|
-- Get archive statistics
|
||||||
local stats = reader:getStats()
|
local stats = reader:getStats()
|
||||||
print(string.format([[
|
print(string.format(
|
||||||
|
[[
|
||||||
|
|
||||||
Archive stats:
|
Archive stats:
|
||||||
Files: %d
|
Files: %d
|
||||||
Directories: %d
|
Directories: %d
|
||||||
Total size: %d bytes]],
|
Total size: %d bytes]],
|
||||||
stats.fileCount,
|
stats.fileCount,
|
||||||
stats.dirCount,
|
stats.dirCount,
|
||||||
stats.totalSize
|
stats.totalSize
|
||||||
))
|
))
|
||||||
|
|
32
lib/crc.luau
32
lib/crc.luau
|
@ -2,29 +2,29 @@ local CRC32_TABLE = table.create(256)
|
||||||
|
|
||||||
-- Initialize the lookup table and lock it in place
|
-- Initialize the lookup table and lock it in place
|
||||||
for i = 0, 255 do
|
for i = 0, 255 do
|
||||||
local crc = i
|
local crc = i
|
||||||
for _ = 1, 8 do
|
for _ = 1, 8 do
|
||||||
if bit32.band(crc, 1) == 1 then
|
if bit32.band(crc, 1) == 1 then
|
||||||
crc = bit32.bxor(bit32.rshift(crc, 1), 0xEDB88320)
|
crc = bit32.bxor(bit32.rshift(crc, 1), 0xEDB88320)
|
||||||
else
|
else
|
||||||
crc = bit32.rshift(crc, 1)
|
crc = bit32.rshift(crc, 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
CRC32_TABLE[i] = crc
|
CRC32_TABLE[i] = crc
|
||||||
end
|
end
|
||||||
|
|
||||||
table.freeze(CRC32_TABLE)
|
table.freeze(CRC32_TABLE)
|
||||||
|
|
||||||
local function crc32(buf: buffer): number
|
local function crc32(buf: buffer): number
|
||||||
local crc = 0xFFFFFFFF
|
local crc = 0xFFFFFFFF
|
||||||
|
|
||||||
for i = 0, buffer.len(buf) - 1 do
|
for i = 0, buffer.len(buf) - 1 do
|
||||||
local byte = buffer.readu8(buf, i)
|
local byte = buffer.readu8(buf, i)
|
||||||
local index = bit32.band(bit32.bxor(crc, byte), 0xFF)
|
local index = bit32.band(bit32.bxor(crc, byte), 0xFF)
|
||||||
crc = bit32.bxor(bit32.rshift(crc, 8), CRC32_TABLE[index])
|
crc = bit32.bxor(bit32.rshift(crc, 8), CRC32_TABLE[index])
|
||||||
end
|
end
|
||||||
|
|
||||||
return bit32.bxor(crc, 0xFFFFFFFF)
|
return bit32.bxor(crc, 0xFFFFFFFF)
|
||||||
end
|
end
|
||||||
|
|
||||||
return crc32
|
return crc32
|
||||||
|
|
|
@ -27,7 +27,7 @@ export type DataInner = {
|
||||||
dest: buffer,
|
dest: buffer,
|
||||||
destLen: number,
|
destLen: number,
|
||||||
|
|
||||||
ltree: Tree,
|
ltree: Tree,
|
||||||
dtree: Tree,
|
dtree: Tree,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,8 +270,10 @@ function ZipReader.extract(self: ZipReader, entry: ZipEntry, options: Extraction
|
||||||
local optionsOrDefault: {
|
local optionsOrDefault: {
|
||||||
decompress: boolean,
|
decompress: boolean,
|
||||||
isString: boolean,
|
isString: boolean,
|
||||||
skipValidation: boolean
|
skipValidation: boolean,
|
||||||
} = if options then setmetatable(options, { __index = defaultOptions }) :: any else defaultOptions
|
} = if options
|
||||||
|
then setmetatable(options, { __index = defaultOptions }) :: any
|
||||||
|
else defaultOptions
|
||||||
|
|
||||||
local pos = entry.offset
|
local pos = entry.offset
|
||||||
if buffer.readu32(self.data, pos) ~= SIGNATURES.LOCAL_FILE then
|
if buffer.readu32(self.data, pos) ~= SIGNATURES.LOCAL_FILE then
|
||||||
|
|
131
pesde.lock
131
pesde.lock
|
@ -2,6 +2,80 @@ name = "0x5eal/unzip"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
target = "luau"
|
target = "luau"
|
||||||
|
|
||||||
|
[graph."jiwonz/dirs"."0.1.2 lune"]
|
||||||
|
resolved_ty = "standard"
|
||||||
|
|
||||||
|
[graph."jiwonz/dirs"."0.1.2 lune".target]
|
||||||
|
environment = "lune"
|
||||||
|
lib = "src/init.luau"
|
||||||
|
|
||||||
|
[graph."jiwonz/dirs"."0.1.2 lune".dependencies]
|
||||||
|
"jiwonz/pathfs" = ["0.1.0 lune", "pathfs"]
|
||||||
|
|
||||||
|
[graph."jiwonz/dirs"."0.1.2 lune".pkg_ref]
|
||||||
|
ref_ty = "pesde"
|
||||||
|
name = "jiwonz/dirs"
|
||||||
|
version = "0.1.2"
|
||||||
|
index_url = "https://github.com/daimond113/pesde-index"
|
||||||
|
|
||||||
|
[graph."jiwonz/dirs"."0.1.2 lune".pkg_ref.dependencies]
|
||||||
|
pathfs = [{ name = "jiwonz/pathfs", version = "^0.1.0", index = "https://github.com/daimond113/pesde-index" }, "standard"]
|
||||||
|
|
||||||
|
[graph."jiwonz/dirs"."0.1.2 lune".pkg_ref.target]
|
||||||
|
environment = "lune"
|
||||||
|
lib = "src/init.luau"
|
||||||
|
|
||||||
|
[graph."jiwonz/pathfs"."0.1.0 lune"]
|
||||||
|
resolved_ty = "standard"
|
||||||
|
|
||||||
|
[graph."jiwonz/pathfs"."0.1.0 lune".target]
|
||||||
|
environment = "lune"
|
||||||
|
lib = "init.luau"
|
||||||
|
|
||||||
|
[graph."jiwonz/pathfs"."0.1.0 lune".pkg_ref]
|
||||||
|
ref_ty = "pesde"
|
||||||
|
name = "jiwonz/pathfs"
|
||||||
|
version = "0.1.0"
|
||||||
|
index_url = "https://github.com/daimond113/pesde-index"
|
||||||
|
|
||||||
|
[graph."jiwonz/pathfs"."0.1.0 lune".pkg_ref.target]
|
||||||
|
environment = "lune"
|
||||||
|
lib = "init.luau"
|
||||||
|
|
||||||
|
[graph."lukadev_0/option"."1.2.0 lune"]
|
||||||
|
resolved_ty = "standard"
|
||||||
|
|
||||||
|
[graph."lukadev_0/option"."1.2.0 lune".target]
|
||||||
|
environment = "lune"
|
||||||
|
lib = "lib/init.luau"
|
||||||
|
|
||||||
|
[graph."lukadev_0/option"."1.2.0 lune".pkg_ref]
|
||||||
|
ref_ty = "pesde"
|
||||||
|
name = "lukadev_0/option"
|
||||||
|
version = "1.2.0"
|
||||||
|
index_url = "https://github.com/daimond113/pesde-index"
|
||||||
|
|
||||||
|
[graph."lukadev_0/option"."1.2.0 lune".pkg_ref.target]
|
||||||
|
environment = "lune"
|
||||||
|
lib = "lib/init.luau"
|
||||||
|
|
||||||
|
[graph."lukadev_0/result"."1.2.0 lune"]
|
||||||
|
resolved_ty = "standard"
|
||||||
|
|
||||||
|
[graph."lukadev_0/result"."1.2.0 lune".target]
|
||||||
|
environment = "lune"
|
||||||
|
lib = "lib/init.luau"
|
||||||
|
|
||||||
|
[graph."lukadev_0/result"."1.2.0 lune".pkg_ref]
|
||||||
|
ref_ty = "pesde"
|
||||||
|
name = "lukadev_0/result"
|
||||||
|
version = "1.2.0"
|
||||||
|
index_url = "https://github.com/daimond113/pesde-index"
|
||||||
|
|
||||||
|
[graph."lukadev_0/result"."1.2.0 lune".pkg_ref.target]
|
||||||
|
environment = "lune"
|
||||||
|
lib = "lib/init.luau"
|
||||||
|
|
||||||
[graph."lukadev_0/result"."1.2.0 luau"]
|
[graph."lukadev_0/result"."1.2.0 luau"]
|
||||||
direct = ["result", { name = "lukadev_0/result", version = "^1.2.0" }, "standard"]
|
direct = ["result", { name = "lukadev_0/result", version = "^1.2.0" }, "standard"]
|
||||||
resolved_ty = "standard"
|
resolved_ty = "standard"
|
||||||
|
@ -19,3 +93,60 @@ index_url = "https://github.com/pesde-pkg/index"
|
||||||
[graph."lukadev_0/result"."1.2.0 luau".pkg_ref.target]
|
[graph."lukadev_0/result"."1.2.0 luau".pkg_ref.target]
|
||||||
environment = "luau"
|
environment = "luau"
|
||||||
lib = "lib/init.luau"
|
lib = "lib/init.luau"
|
||||||
|
|
||||||
|
[graph."pesde/stylua"."2.0.2 lune"]
|
||||||
|
direct = ["stylua", { name = "pesde/stylua", version = "^2.0.2", target = "lune" }, "dev"]
|
||||||
|
resolved_ty = "dev"
|
||||||
|
|
||||||
|
[graph."pesde/stylua"."2.0.2 lune".target]
|
||||||
|
environment = "lune"
|
||||||
|
bin = "init.luau"
|
||||||
|
|
||||||
|
[graph."pesde/stylua"."2.0.2 lune".dependencies]
|
||||||
|
"lukadev_0/option" = ["1.2.0 lune", "option"]
|
||||||
|
"lukadev_0/result" = ["1.2.0 lune", "result"]
|
||||||
|
"pesde/toolchainlib" = ["0.1.7 lune", "core"]
|
||||||
|
|
||||||
|
[graph."pesde/stylua"."2.0.2 lune".pkg_ref]
|
||||||
|
ref_ty = "pesde"
|
||||||
|
name = "pesde/stylua"
|
||||||
|
version = "2.0.2"
|
||||||
|
index_url = "https://github.com/pesde-pkg/index"
|
||||||
|
|
||||||
|
[graph."pesde/stylua"."2.0.2 lune".pkg_ref.dependencies]
|
||||||
|
core = [{ name = "pesde/toolchainlib", version = "^0.1.3", index = "https://github.com/daimond113/pesde-index", target = "lune" }, "standard"]
|
||||||
|
option = [{ name = "lukadev_0/option", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "standard"]
|
||||||
|
result = [{ name = "lukadev_0/result", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "standard"]
|
||||||
|
|
||||||
|
[graph."pesde/stylua"."2.0.2 lune".pkg_ref.target]
|
||||||
|
environment = "lune"
|
||||||
|
bin = "init.luau"
|
||||||
|
|
||||||
|
[graph."pesde/toolchainlib"."0.1.7 lune"]
|
||||||
|
resolved_ty = "standard"
|
||||||
|
|
||||||
|
[graph."pesde/toolchainlib"."0.1.7 lune".target]
|
||||||
|
environment = "lune"
|
||||||
|
lib = "src/init.luau"
|
||||||
|
|
||||||
|
[graph."pesde/toolchainlib"."0.1.7 lune".dependencies]
|
||||||
|
"jiwonz/dirs" = ["0.1.2 lune", "dirs"]
|
||||||
|
"jiwonz/pathfs" = ["0.1.0 lune", "pathfs"]
|
||||||
|
"lukadev_0/option" = ["1.2.0 lune", "option"]
|
||||||
|
"lukadev_0/result" = ["1.2.0 lune", "result"]
|
||||||
|
|
||||||
|
[graph."pesde/toolchainlib"."0.1.7 lune".pkg_ref]
|
||||||
|
ref_ty = "pesde"
|
||||||
|
name = "pesde/toolchainlib"
|
||||||
|
version = "0.1.7"
|
||||||
|
index_url = "https://github.com/daimond113/pesde-index"
|
||||||
|
|
||||||
|
[graph."pesde/toolchainlib"."0.1.7 lune".pkg_ref.dependencies]
|
||||||
|
dirs = [{ name = "jiwonz/dirs", version = "^0.1.1", index = "https://github.com/daimond113/pesde-index" }, "standard"]
|
||||||
|
option = [{ name = "lukadev_0/option", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "peer"]
|
||||||
|
pathfs = [{ name = "jiwonz/pathfs", version = "^0.1.0", index = "https://github.com/daimond113/pesde-index" }, "standard"]
|
||||||
|
result = [{ name = "lukadev_0/result", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "peer"]
|
||||||
|
|
||||||
|
[graph."pesde/toolchainlib"."0.1.7 lune".pkg_ref.target]
|
||||||
|
environment = "lune"
|
||||||
|
lib = "src/init.luau"
|
||||||
|
|
|
@ -13,3 +13,6 @@ default = "https://github.com/pesde-pkg/index"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
result = { name = "lukadev_0/result", version = "^1.2.0" }
|
result = { name = "lukadev_0/result", version = "^1.2.0" }
|
||||||
|
|
||||||
|
[dev_dependencies]
|
||||||
|
stylua = { name = "pesde/stylua", version = "^2.0.2", target = "lune" }
|
||||||
|
|
Loading…
Add table
Reference in a new issue