merge ws/arch2-unix (cpio, ar/deb, rpm, z, iso, lz4; containers/Cpio, Iso9660; codecs UnixCompress, Xxh32, Lz4 from ws/roblox)
This commit is contained in:
commit
242e38c4fe
36 files changed
+5171
-7
No files matched your search
@@ -53,24 +53,31 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| font | pcf | .pcf | yes | - | bitmap: true | `tests/font/pcf.luau` |
|
||||
| font | psf | .psf .psfu | yes | yes | bitmap: true, variants: "psf1", "psf2" | `tests/font/psf.luau` |
|
||||
| font | ttf | .ttf .otf .ttc .otc | yes | - | outlines: "truetype", "cff", collection: true, kerning: true | `tests/font/ttf.luau` |
|
||||
| font | type1 | .pfb .pfa .t1 | yes | - | outlines: "type1", variants: "pfb", "pfa" | **missing** |
|
||||
| font | woff | .woff | yes | - | outlines: "truetype", "cff" | `tests/font/woff.luau` |
|
||||
| font | woff2 | .woff2 | yes | - | outlines: "truetype", "cff", transforms: "glyf", "loca", "hmtx" | `tests/font/woff2.luau` |
|
||||
| archive | 7z | .7z | yes | - | methods: "copy", "lzma", "lzma2", "deflate", "bcj", "delta", encrypted: false | `tests/archive/7z.luau` |
|
||||
| archive | adf | .adf | yes | - | variants: "ofs", "ffs" | `tests/archive/adf.luau` |
|
||||
| archive | applesingle | .as .applesingle .appledouble | yes | yes | forks: true, variants: "applesingle", "appledouble" | `tests/archive/applesingle.luau` |
|
||||
| archive | ar | .a .ar .deb .lib | yes | yes | variants: "gnu", "bsd", deb: true | `tests/archive/ar.luau` |
|
||||
| archive | arj | .arj | yes | - | methods: "store", "arj1", "arj2", "arj3", "arj4" | `tests/archive/arj.luau` |
|
||||
| archive | binhex | .hqx .hcx | yes | yes | forks: true | `tests/archive/binhex.luau` |
|
||||
| archive | br | .br | yes | - | stream: true | `tests/archive/br.luau` |
|
||||
| archive | bz2 | .bz2 .tbz2 .tbz | yes | - | stream: true | `tests/archive/bz2.luau` |
|
||||
| archive | cpio | .cpio | yes | yes | variants: "newc", "crc", "odc", "bin" | `tests/archive/cpio.luau` |
|
||||
| archive | d64 | .d64 .d71 .d81 | yes | yes | variants: "d64", "d71", "d81" | `tests/archive/d64.luau` |
|
||||
| archive | fat | .img .ima .vfd .flp .fat | yes | yes | variants: "fat12", "fat16", "fat32" | `tests/archive/fat.luau` |
|
||||
| archive | gzip | .gz .tgz .gzip | yes | yes | stream: true | `tests/archive/gzip.luau` |
|
||||
| archive | iso | .iso | yes | - | extensions: "joliet", "rockridge", "eltorito" | `tests/archive/iso.luau` |
|
||||
| archive | lha | .lzh .lha .lzs | yes | yes | methods: "lh0", "lh1", "lh4", "lh5", "lh6", "lh7", "lhx", "lzs", "lz5", "lz4", "lhd" | `tests/archive/lha.luau` |
|
||||
| archive | lz4 | .lz4 .tlz4 | yes | yes | stream: true, legacy: true | `tests/archive/lz4.luau` |
|
||||
| archive | macbinary | .bin .macbin | yes | yes | forks: true, variants: "I", "II", "III" | `tests/archive/macbinary.luau` |
|
||||
| archive | rpm | .rpm | yes | - | compressors: "gzip", "bzip2", "xz", "lzma", "zstd" | `tests/archive/rpm.luau` |
|
||||
| archive | tar | .tar | yes | yes | variants: "ustar", "pax", "gnu" | `tests/archive/tar.luau` |
|
||||
| archive | uu | .uu .uue .xxe .b64 | yes | yes | variants: "uu", "xx", "base64" | `tests/archive/uu.luau` |
|
||||
| archive | xz | .xz .txz .lzma | yes | - | stream: true, filters: "lzma2", "lzma", "delta", "x86", "powerpc", "arm", "armthumb", "sparc", "arm64" | `tests/archive/xz.luau` |
|
||||
| archive | yenc | .yenc .ync | yes | yes | multipart: true | `tests/archive/yenc.luau` |
|
||||
| archive | z | .z .taz .tz | yes | yes | stream: true, bits: 9, 16 | `tests/archive/z.luau` |
|
||||
| archive | zip | .zip .wsz | yes | yes | methods: "store", "deflate", zip64: true | `tests/archive/zip.luau` |
|
||||
| archive | zoo | .zoo | yes | - | methods: "store", "lzw", "lzh" | `tests/archive/zoo.luau` |
|
||||
| archive | zst | .zst .tzst | yes | - | stream: true | `tests/archive/zst.luau` |
|
||||
@@ -120,10 +127,13 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
- codecs/compress/Brotli: Brotli (RFC 7932) decompression. A codec (layer 3): archive/br and font/woff2 build on it. Written
|
||||
- codecs/compress/Bzip2: bzip2 decompressor (BWT + MTF + Huffman, the .bz2 stream format of bzip2 0.9.5 / 1.0.x). A codec
|
||||
- codecs/compress/Deflate: DEFLATE (RFC 1951) decoder and compressor, with the zlib (RFC 1950) and gzip (RFC 1952) wrappers.
|
||||
- codecs/compress/Lz4: the LZ4 block format (lz4 doc/lz4_Block_format.md): decode and a greedy hash-chain-free encoder
|
||||
- codecs/compress/Lzh: the LHA family of LZSS decoders, used by archive/lha, archive/arj and archive/zoo:
|
||||
- codecs/compress/Lzma: LZMA and LZMA2 decoders, the .lzma ("LZMA alone") wrapper and the .xz container. A codec (layer 3):
|
||||
- codecs/compress/Lzw: LZW decoder and encoder in the two variants file formats use. A codec (layer 1): image/gif and
|
||||
- codecs/compress/PackBits: the Apple PackBits run-length code (TIFF compression 32773, PSD / PSB RLE channels, IFF
|
||||
- codecs/compress/UnixCompress: the LZW of Unix compress (.Z files: magic 1F 9D, a flags byte with the maximum code
|
||||
- codecs/compress/Xxh32: XXH32 of a buffer range (any seed), for the LZ4 frame format's header, block and content
|
||||
- codecs/compress/Zstd: Zstandard decompression (RFC 8878). A codec (layer 3): archive/zst and anything else carrying zstd
|
||||
- **entropy**
|
||||
- codecs/entropy/Huffman: canonical Huffman codes (RFC 1951 3.2.2 / JPEG Annex C order) for decoders and encoders.
|
||||
@@ -131,6 +141,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
- **font**
|
||||
- codecs/font/Bitmap: the standard Font value for bitmap fonts (BDF, PCF, PSF, Windows FON / FNT): a Types.BitmapStrike
|
||||
- codecs/font/Cff: Compact Font Format (Adobe TN #5176) and Type 2 charstrings (TN #5177): the outlines of OpenType fonts
|
||||
- codecs/font/GlyphNames: PostScript glyph names -> Unicode for fonts that name their glyphs (Type 1, CFF without a
|
||||
- codecs/font/TrueType: the sfnt font container (TrueType .ttf, OpenType .otf with CFF outlines, collections .ttc) parsed
|
||||
- **image**
|
||||
- codecs/image/Blend: layer compositing on rgba8 buffers (straight alpha): source-over with the separable and non-separable
|
||||
|
||||
+99
-6
@@ -25,7 +25,7 @@ assert(F.archive.load(out):read("notes/todo.txt"))
|
||||
| Field / method | Type | Meaning |
|
||||
|---|---|---|
|
||||
| `kind` | `"archive"` | |
|
||||
| `format` | string | `"zip"`, `"tar"`, `"7z"`, `"gzip"`, `"xz"`, `"zst"`, `"bz2"`, `"br"` |
|
||||
| `format` | string | `"zip"`, `"tar"`, `"7z"`, `"gzip"`, `"xz"`, `"zst"`, `"bz2"`, `"br"`, `"cpio"`, `"ar"`, `"rpm"`, `"z"`, `"lz4"`, `"iso"` |
|
||||
| `list(self)` | `{ ArchiveEntry }` | the entries in archive order (directories included) |
|
||||
| `read(self, name)` | `buffer?, Err?` | a fresh copy of the entry's bytes, decompressed (lazily, on each call) |
|
||||
| `add(self, name, data, opts?)` | | add or replace an entry; `data` is a buffer or a string |
|
||||
@@ -43,7 +43,7 @@ assert(F.archive.load(out):read("notes/todo.txt"))
|
||||
| `mtime` | number? | modification time, Unix seconds (UTC) |
|
||||
| `dir` | boolean | a directory entry |
|
||||
| `crc32`, `comment` | number?, string? | zip only |
|
||||
| `mode`, `uid`, `gid`, `uname`, `gname`, `type`, `link` | | tar only (`mode` is the Unix permission bits, e.g. `420` = `0644`) |
|
||||
| `mode`, `uid`, `gid`, `uname`, `gname`, `type`, `link` | | tar, cpio, ar, rpm, iso (`mode` is the Unix permission bits, e.g. `420` = `0644`) |
|
||||
|
||||
## Load
|
||||
|
||||
@@ -85,11 +85,12 @@ Options for loading:
|
||||
|
||||
| Option | Formats | Meaning |
|
||||
|---|---|---|
|
||||
| `unwrap` | gzip, xz, zst, bz2, br | `false`: do not open an archive inside a single-stream file (also off when `format` is given) |
|
||||
| `unwrap` | gzip, xz, zst, bz2, br, z, lz4, deb | `false`: do not open an archive inside a single-stream file or a `.deb` (also off when `format` is given) |
|
||||
| `name` | single-stream | the file name, used to name the entry (set for you when loading a path) |
|
||||
| `verify` | zip | check each entry's CRC-32 on read (default `true`) |
|
||||
| `maxEntries` | tar | refuse more entries (default 1e6) |
|
||||
| `maxBytes` | bz2, br | refuse a bigger decompressed size |
|
||||
| `verify` | zip, lz4, cpio | check each entry's CRC-32 on read (zip), the XXH32 checksums (lz4), the crc sums (cpio) (default `true`) |
|
||||
| `maxEntries` | tar, cpio, ar, rpm, iso | refuse more entries (default 1e6) |
|
||||
| `prefer` | iso | the name set: `"rockridge"`, `"joliet"` or `"iso9660"` (default: the richest present) |
|
||||
| `maxBytes` | bz2, br, rpm, z, lz4 | refuse a bigger decompressed size |
|
||||
|
||||
A path works on hosts with a file system:
|
||||
|
||||
@@ -185,6 +186,92 @@ local gzipped = assert(F.save("some text", nil, { format = "gzip", name = "note.
|
||||
assert(F.archive.load(gzipped, { unwrap = false }):list()[1].name == "note.txt")
|
||||
```
|
||||
|
||||
## Unix, package and disc archives
|
||||
|
||||
### cpio
|
||||
|
||||
GNU cpio's and bsdtar's newc, crc, odc and old binary archives read; newc, crc and odc write (`variant`, default the
|
||||
source's). Entries carry the Unix fields: `type` (tar letters: `"0"` file, `"5"` directory, `"2"` symlink, ...),
|
||||
`mode`, `uid`, `gid`, `nlink`, `ino`, device numbers, `link`, and `hardlink` (every link of a hard-linked file reads
|
||||
its data).
|
||||
|
||||
```luau
|
||||
local cpio = assert(F.archive.load(cpioBytes))
|
||||
local by = {}
|
||||
for _, e in cpio:list() do
|
||||
by[e.name] = e
|
||||
end
|
||||
assert(by["bin"].dir and by["bin/run.sh"].mode == 493) -- 493 = 0755
|
||||
assert(by["run"].type == "2" and by["run"].link == "bin/run.sh") -- a symlink
|
||||
local odc = assert(cpio:write({ variant = "odc" }))
|
||||
assert(F.archive.load(odc).meta.source.variant == "odc")
|
||||
```
|
||||
|
||||
### ar and .deb
|
||||
|
||||
Unix `ar` archives (GNU / System V long names and symbol tables, BSD `#1/` names) read and write (`variant = "gnu"`
|
||||
or `"bsd"`); symbols land in `meta.symbols`. A `.deb` loads as its `data.tar.*` (any compression), with the ar
|
||||
archive in `meta.outer` and the control file's fields in `meta.outer.meta.control`:
|
||||
|
||||
```luau
|
||||
local deb = assert(F.archive.load(debBytes))
|
||||
assert(deb.format == "tar" and deb.meta.container == "ar")
|
||||
assert(deb:read("./usr/bin/hello"))
|
||||
local control = deb.meta.outer.meta.control
|
||||
assert(control.Package == "hello" and control.Version == "1.0-1")
|
||||
local ar = assert(F.archive.load(debBytes, { unwrap = false })) -- the ar itself
|
||||
assert(ar:list()[1].name == "debian-binary" and ar.meta.payload == "data.tar.xz")
|
||||
```
|
||||
|
||||
### rpm
|
||||
|
||||
RPM packages list from their header (no decompression); the payload (gzip, bzip2, xz, lzma or zstd) is decompressed
|
||||
on the first `read`. The header fields are in `meta.rpm` (`name`, `version`, `release`, `arch`, `summary`, ... and
|
||||
every tag by number in `meta.rpm.tags`). Read only.
|
||||
|
||||
```luau
|
||||
local rpm = assert(F.archive.load(rpmBytes))
|
||||
assert(rpm.meta.rpm.name == "hello" and rpm.meta.rpm.version == "1.0" and rpm.meta.rpm.arch == "noarch")
|
||||
assert(rpm:list()[1].name == "usr/bin/hello" and rpm:list()[1].mode == 493)
|
||||
local hello = buffer.tostring(assert(rpm:read("usr/bin/hello")))
|
||||
assert(string.find(hello, "echo hello", 1, true))
|
||||
```
|
||||
|
||||
### .Z and .lz4
|
||||
|
||||
Unix `compress` (`.Z`, `.taz`) and LZ4 frame (`.lz4`) files are single-stream archives like gzip: a `.tar.Z` or
|
||||
`.tar.lz4` loads as the tar. Both write: `.Z` byte for byte as ncompress (`maxBits` 9..16), `.lz4` as one frame of
|
||||
independent blocks (`blockSize`, `blockChecksum`, `contentChecksum`, `contentSize`).
|
||||
|
||||
```luau
|
||||
local tar = assert(F.archive.load(tarZBytes))
|
||||
assert(tar.format == "tar" and tar.meta.compression == "z")
|
||||
local lz = assert(F.archive.load(lz4Bytes, { name = "notes.txt.lz4" }))
|
||||
assert(lz.meta.stream and lz:list()[1].name == "notes.txt")
|
||||
local z = assert(F.save(tar, nil, { format = "z" })) -- a tar inside
|
||||
assert(F.archive.load(z).format == "tar")
|
||||
local l4 = assert(F.save("some text", nil, { format = "lz4", blockChecksum = true }))
|
||||
assert(buffer.tostring(F.archive.load(l4):read("data")) == "some text")
|
||||
```
|
||||
|
||||
### ISO images
|
||||
|
||||
ISO 9660 images read with Rock Ridge names, modes and symlinks when present, else Joliet's Unicode names, else the
|
||||
plain ISO names (`prefer = "joliet"` / `"iso9660"` picks another set). `meta.iso` has the volume facts and
|
||||
`meta.boot` an El Torito boot catalog. Read only.
|
||||
|
||||
```luau
|
||||
local iso = assert(F.archive.load(isoBytes))
|
||||
assert(iso.meta.iso.volumeId == "DOCS" and iso.meta.iso.rockRidge and iso.meta.iso.joliet)
|
||||
assert(iso.meta.boot and iso.meta.boot.bootable)
|
||||
local by = {}
|
||||
for _, e in iso:list() do
|
||||
by[e.name] = e
|
||||
end
|
||||
assert(by["bin"].dir and by["bin/run.sh"].mode == 493 and by["run"].link == "bin/run.sh")
|
||||
assert(F.archive.load(isoBytes, { prefer = "joliet" }).meta.iso.tree == "joliet")
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
@@ -197,6 +284,12 @@ assert(F.archive.load(gzipped, { unwrap = false }):list()[1].name == "note.txt")
|
||||
| zstd (`.zst`, `.tzst`) | yes | - | single stream; no dictionaries |
|
||||
| bzip2 (`.bz2`, `.tbz2`) | yes | - | single stream |
|
||||
| Brotli (`.br`) | yes | - | single stream; no magic number, so pass a `.br` name or `format = "br"` |
|
||||
| cpio (`.cpio`) | yes | yes | newc, crc, odc, old binary (read); hard links, symlinks, devices |
|
||||
| ar (`.a`, `.ar`, `.deb`) | yes | yes | GNU / BSD names, symbol tables; a `.deb` loads as its data tar |
|
||||
| rpm (`.rpm`) | yes | - | gzip / bzip2 / xz / lzma / zstd payloads |
|
||||
| compress (`.Z`, `.taz`) | yes | yes | single stream; 9..16-bit LZW |
|
||||
| LZ4 (`.lz4`) | yes | yes | single stream; frames, legacy frames, XXH32 checks; no dictionaries |
|
||||
| ISO 9660 (`.iso`) | yes | - | Joliet, Rock Ridge, El Torito, multi-extent; no UDF |
|
||||
|
||||
Full capability list: [FORMATS.md](../FORMATS.md).
|
||||
|
||||
|
||||
Reference in new issue
Block a user