This commit is contained in:
2026-01-18 08:54:48 -06:00
parent a7a323a74e
commit bbd2d298ba
18 changed files with 258 additions and 256 deletions

View File

@@ -24,12 +24,12 @@ function list(archive_path) {
}
var files = archive.list()
for (var f of files) {
arrfor(files, function(f) {
var s = archive.stat(f)
// Format: index hash size path
// We don't have index/hash easily available in JS binding yet, just size/path
log.console(`${f} (${s.size} bytes)`)
}
})
archive.close()
}
@@ -48,7 +48,7 @@ function unpack(archive_path) {
}
var files = archive.list()
for (var f of files) {
arrfor(files, function(f) {
var data = archive.read(f)
if (data) {
// Ensure directory exists
@@ -57,17 +57,17 @@ function unpack(archive_path) {
// recursive mkdir
var parts = array(dir, '/')
var curr = "."
for (var p of parts) {
arrfor(parts, function(p) {
curr += "/" + p
try { fd.mkdir(curr) } catch(e) {}
}
})
}
var fh = fd.open(f, "w")
fd.write(fh, data)
fd.close(fh)
log.console("Extracted " + f)
}
}
})
archive.close()
}
@@ -89,11 +89,11 @@ function pack(sources, archive_path, read_dir) {
if (st.isDirectory) {
var list = fd.readdir(full_path)
for (var item of list) {
if (item == "." || item == "..") continue
arrfor(list, function(item) {
if (item == "." || item == "..") return
var sub = path == "." ? item : path + "/" + item
add_recursive(sub)
}
})
} else {
var data = fd.slurp(full_path)
if (data) {
@@ -103,9 +103,9 @@ function pack(sources, archive_path, read_dir) {
}
}
for (var s of sources) {
arrfor(sources, function(s) {
add_recursive(s)
}
})
writer.finalize()
log.console("Created " + archive_path)