mirror of
https://github.com/0x5eal/luau-unzip.git
synced 2025-04-10 17:20:53 +01:00
chore(examples): slightly refactor tour
example
This commit is contained in:
parent
1f4dd5715b
commit
6f4083f10f
1 changed files with 10 additions and 20 deletions
|
@ -1,4 +1,5 @@
|
||||||
local fs = require("@lune/fs")
|
local fs = require("@lune/fs")
|
||||||
|
local stdio = require("@lune/stdio")
|
||||||
local zip = require("../lib")
|
local zip = require("../lib")
|
||||||
|
|
||||||
local file = fs.readFile("test.zip")
|
local file = fs.readFile("test.zip")
|
||||||
|
@ -7,32 +8,21 @@ 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), content: %s", entry.size, stdio.format(reader:extract(entry) :: string))
|
||||||
|
else ""
|
||||||
print(prefix .. entry.name .. suffix)
|
print(prefix .. entry.name .. suffix)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- FIXME: Duplicates in directory listings when using `zip -r`
|
print("\Children 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 "FILE"}`)
|
||||||
if not entry.isDirectory then
|
|
||||||
local extracted = reader:extract(entry, { isString = true })
|
|
||||||
print(" -> Content:", extracted)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get archive statistics
|
-- Get archive statistics
|
||||||
local stats = reader:getStats()
|
local stats = reader:getStats()
|
||||||
print(string.format(
|
print("\nArchive stats:")
|
||||||
[[
|
print("Files:", stats.fileCount)
|
||||||
|
print("Directories:", stats.dirCount)
|
||||||
Archive stats:
|
print("Total size:", stats.totalSize, "bytes")
|
||||||
Files: %d
|
|
||||||
Directories: %d
|
|
||||||
Total size: %d bytes]],
|
|
||||||
stats.fileCount,
|
|
||||||
stats.dirCount,
|
|
||||||
stats.totalSize
|
|
||||||
))
|
|
Loading…
Add table
Reference in a new issue