From 6f4083f10f42c8d100205a98cafc2b32216f3978 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Thu, 2 Jan 2025 06:07:23 +0000 Subject: [PATCH] chore(examples): slightly refactor `tour` example --- examples/tour.luau | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/examples/tour.luau b/examples/tour.luau index d57bd0d..b3e031e 100644 --- a/examples/tour.luau +++ b/examples/tour.luau @@ -1,4 +1,5 @@ local fs = require("@lune/fs") +local stdio = require("@lune/stdio") local zip = require("../lib") local file = fs.readFile("test.zip") @@ -7,32 +8,21 @@ local reader = zip.load(buffer.fromstring(file)) print("Directory structure:") reader:walk(function(entry, 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) end) --- FIXME: Duplicates in directory listings when using `zip -r` - -print("\nContents of `/`:") +print("\Children of `/`:") local assets = reader:listDirectory("/") for _, entry in assets do - print(" ->", entry.name, if entry.isDirectory then "DIR" else entry.size) - if not entry.isDirectory then - local extracted = reader:extract(entry, { isString = true }) - print(" -> Content:", extracted) - end + print(` {entry.name} - {if entry.isDirectory then "DIR" else "FILE"}`) end -- Get archive statistics local stats = reader:getStats() -print(string.format( - [[ - -Archive stats: -Files: %d -Directories: %d -Total size: %d bytes]], - stats.fileCount, - stats.dirCount, - stats.totalSize -)) +print("\nArchive stats:") +print("Files:", stats.fileCount) +print("Directories:", stats.dirCount) +print("Total size:", stats.totalSize, "bytes") \ No newline at end of file