archive formats: comments are specs only

This commit is contained in:
4DBug committed 2026-11-01 01:53:52 -05:00
1 parent 8bd1a9327c
commit e792c419d9
36 files changed
+172 -442

No files matched your search

+7 -18
View File
@@ -1,13 +1,7 @@
--!strict
-- archive/lz4: LZ4 frame files (.lz4: lz4 doc/lz4_Frame_format.md 1.6.x) as a single-stream Archive: one entry (the
-- decompressed data), named after the file without .lz4 (.tlz4 -> .tar), else "data"; meta.stream = true, so the api
-- unwraps a .tar.lz4. Reading: concatenated frames, skippable frames (magic 0x184D2A50..5F, skipped), the legacy
-- frame (magic 0x184C2102, 8 MB blocks), independent and linked blocks, block sizes 64 KB .. 4 MB, uncompressed
-- blocks, the header checksum, block checksums and the content checksum (XXH32, codecs/compress/Xxh32: verified
-- unless opts.verify = false), the content size (checked). Writing: one frame of independent blocks
-- (codecs/compress/Lz4), with opts for the block size, block checksums, the content checksum and the content size;
-- several entries are written as a tar inside. Written from the specification; no code ported. Not supported:
-- dictionaries (frames with a dictionary ID: Err.UNSUPPORTED), writing linked blocks or legacy frames.
-- archive/lz4: LZ4 frames (lz4_Frame_format.md 1.6.x) as a single-stream archive. Supports: concatenated, skippable
-- (0x184D2A50..5F) and legacy (0x184C2102, 8 MB blocks) frames, linked blocks, 64 KB .. 4 MB, XXH32 checksums; writes
-- one frame of independent blocks. Not supported: dictionaries, writing linked blocks or legacy frames.
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
@@ -27,15 +21,15 @@ local Lz4Format = {
}
export type DecodeOptions = {
maxBytes: number?, -- refuse output larger than this (default 2^30)
verify: boolean?, -- check the block / content checksums (default true; the header checksum is always checked)
name: string?, -- the file name (the api passes it): names the entry
maxBytes: number?, -- default 2^30
verify: boolean?, -- default true; the header checksum is always checked
name: string?,
}
export type EncodeOptions = {
blockSize: number?, -- 65536, 262144, 1048576 or 4194304 (default 4 MB, as the lz4 tool)
blockChecksum: boolean?, -- default false
contentChecksum: boolean?, -- default true
contentSize: boolean?, -- store the content size (default false)
contentSize: boolean?, -- default false
}
-- ------------------------------------------------------------------------------------------------ constants
@@ -71,7 +65,6 @@ end
type Out = { buf: buffer, n: number, max: number }
-- room for k more bytes in the output (doubling, up to max) | false
local function room(out: Out, k: number): boolean
local need = out.n + k
if need > out.max then
@@ -85,7 +78,6 @@ local function room(out: Out, k: number): boolean
return true
end
-- one LZ4 frame at p -> the input offset after it | nil, Err
local function frame(b: buffer, p: number, e: number, out: Out, verify: boolean): (number?, Err.Err?)
if p + 7 > e then
return nil, Err.new(Err.TRUNCATED, "frame header past the end", p)
@@ -210,7 +202,6 @@ local function legacy(b: buffer, p: number, e: number, out: Out): (number?, Err.
return q, nil
end
-- decompress(buf, offset?, length?, opts?) -> the data of every frame | nil, Err
function Lz4Format.decompress(src: buffer | string, offset: number?, length: number?, opts: DecodeOptions?): (buffer?, Err.Err?)
local b, o, n, aerr = Bytes.span("Lz4.decompress", src, offset, length)
if not b then
@@ -280,7 +271,6 @@ function Lz4Format.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?
end
-- ------------------------------------------------------------------------------------------------ encode
-- compress(data, opts?) -> one LZ4 frame | nil, Err
function Lz4Format.compress(data: buffer | string, opts: EncodeOptions?): (buffer?, Err.Err?)
local b, o, n, aerr = Bytes.span("Lz4.compress", data, nil, nil)
if not b then
@@ -341,7 +331,6 @@ function Lz4Format.compress(data: buffer | string, opts: EncodeOptions?): (buffe
return w:finish(), nil
end
-- encode(value, opts?): a buffer / string, an Archive's one file, or a tar of the Archive's entries, as one frame
function Lz4Format.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
local data, err = Archive.streamData(value)
if not data then