archive formats: comments are specs only
This commit is contained in:
1 parent
8bd1a9327c
commit
e792c419d9
36 files changed
+172
-442
No files matched your search
@@ -1,11 +1,7 @@
|
||||
--!strict
|
||||
-- archive/uu: uuencoded, xxencoded and GNU "begin-base64" text as an Archive: every "begin <mode> <name>" block of a
|
||||
-- text (mail, news, shar parts: the text around the blocks is ignored) is one entry (entry.mode = the octal mode);
|
||||
-- one block makes a single-stream archive (meta.stream: the api unwraps a uuencoded .tar.gz). The variant of each
|
||||
-- block (uu / xx / base64) is detected from its characters and line lengths and kept in entry.variant and
|
||||
-- meta.source.variant. Written from the POSIX uuencode description and the xxencode alphabet; written as GNU sharutils
|
||||
-- does (45 bytes a line, "`" for zero, base64 lines of 60 characters + "===="). Not supported: multi-part postings
|
||||
-- split over several files (concatenate the parts first), yEnc (archive/yenc), BinHex (archive/binhex).
|
||||
-- archive/uu: uuencode (POSIX), xxencode and GNU "begin-base64" blocks, one entry each (variant detected per block);
|
||||
-- written as GNU sharutils does (45 bytes a line, "`" for zero; base64 60 characters + "===="). Not supported: postings
|
||||
-- split over several files, yEnc (archive/yenc), BinHex (archive/binhex).
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -23,11 +19,11 @@ local Uu = {
|
||||
caps = { decode = true, encode = true, variants = { "uu", "xx", "base64" } },
|
||||
}
|
||||
|
||||
export type DecodeOptions = { maxBytes: number?, name: string? } -- maxBytes: default 2^30
|
||||
export type DecodeOptions = { maxBytes: number?, name: string? } -- default 2^30
|
||||
export type EncodeOptions = {
|
||||
variant: ("uu" | "xx" | "base64")?, -- default "uu"
|
||||
mode: number?, -- file mode when the entry has none (default 0o644)
|
||||
name: string?, -- the name of a buffer / string value (default "data")
|
||||
mode: number?, -- default 0o644
|
||||
name: string?,
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
@@ -50,7 +46,6 @@ function Uu.sniff(r: Bytes.Reader): number
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
-- the value of character c in a variant, or nil
|
||||
local function value(c: number, xx: boolean): number?
|
||||
if xx then
|
||||
return XX_VALUE[c]
|
||||
@@ -61,7 +56,6 @@ local function value(c: number, xx: boolean): number?
|
||||
return nil
|
||||
end
|
||||
|
||||
-- does a data line fit the variant: every character valid and the length matching the count character
|
||||
local function fits(line: string, xx: boolean): boolean
|
||||
local n = value(string.byte(line, 1) or 0, xx)
|
||||
if not n then
|
||||
@@ -79,7 +73,6 @@ local function fits(line: string, xx: boolean): boolean
|
||||
return true
|
||||
end
|
||||
|
||||
-- decode the uu / xx lines of a block into a buffer (nil, message on a bad line)
|
||||
local function decodeLines(lines: { string }, xx: boolean, maxBytes: number): (buffer?, string?)
|
||||
local total = 0
|
||||
for _, l in lines do
|
||||
@@ -266,7 +259,6 @@ function Uu.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ extras
|
||||
-- new() -> an empty uu Archive: a:add(name, data, { mode }); a:write({ variant })
|
||||
function Uu.new(): any
|
||||
local a = Archive.new("uu", encoder)
|
||||
a.meta.source = { format = "uu" }
|
||||
|
||||
Reference in new issue
Block a user