ws-arch2: archive/uu (uuencode / xxencode / base64 blocks, read + write), core/Crc16 (ccitt / arc), Archive.files helper, shared fixture helpers (_arch2.py / _arch2_ours.luau) and tests/archive/_entries.luau
core/Crc16 is new (CRC-16/XMODEM for BinHex / MacBinary, CRC-16/ARC for LHA / Zoo). containers/Archive gains Archive.files(value, name?) (additive).
This commit is contained in:
1 parent
51117f9732
commit
8cdb65367a
10 files changed
+679
No files matched your search
@@ -0,0 +1,43 @@
|
||||
-- tools/fixtures/_arch2_ours.luau: our archive writers' output for the reference tools to read (run by the ws-arch2
|
||||
-- fixture generators through `luau tools/fixtures/_arch2_ours.luau -a <format> [<options as k=v,k=v>]`). Writes the
|
||||
-- standard file set (the same names and bytes as _arch2.FILES) with the format's encoder and prints the file as hex.
|
||||
local F = require("@formats")
|
||||
|
||||
local which, optstr = ...
|
||||
local function content(n: number, seed: number): buffer
|
||||
local b = buffer.create(n)
|
||||
local s = seed
|
||||
for i = 0, n - 1 do
|
||||
s = (s * 75 + 74) % 65537
|
||||
-- runs and noise, so compressors have something to find
|
||||
buffer.writeu8(b, i, if (i // 64) % 3 == 0 then (i // 7) % 256 else s % 256)
|
||||
end
|
||||
return b
|
||||
end
|
||||
|
||||
local opts: { [string]: any } = {}
|
||||
for k, v in string.gmatch(optstr or "", "([%w_]+)=([^,]*)") do
|
||||
opts[k] = tonumber(v) or (if v == "true" then true elseif v == "false" then false else v)
|
||||
end
|
||||
local mod = F.format(which) :: any
|
||||
local a = if mod.new then mod.new() else nil
|
||||
local files = {
|
||||
{ "hello.txt", buffer.fromstring("hello, archive\n") },
|
||||
{ "data.bin", content(5000, 7) },
|
||||
{ "empty.txt", buffer.create(0) },
|
||||
}
|
||||
if opts.single then
|
||||
files = { files[2] }
|
||||
end
|
||||
for _, f in files do
|
||||
a:add(f[1], f[2], { mtime = 1700000000, mode = 0x1A4 })
|
||||
end
|
||||
local out, err = a:write(opts)
|
||||
if not out then
|
||||
error(tostring(err))
|
||||
end
|
||||
local t = table.create(buffer.len(out))
|
||||
for i = 0, buffer.len(out) - 1 do
|
||||
t[i + 1] = string.format("%02x", buffer.readu8(out, i))
|
||||
end
|
||||
print(table.concat(t))
|
||||
Reference in new issue
Block a user