merge ws/arch2: cpio ar/deb rpm .Z lz4 iso lha arj zoo cab, uu/yenc/binhex/macbinary/applesingle, d64 adf fat, bdf pcf psf fon type1 eot hershey
This commit is contained in:
commit
b5cdd77a5b
115 files changed
+17373
-29
No files matched your search
@@ -95,22 +95,47 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| model | x | .x | yes | - | text: true, binary: true, compressed: true, materials: true, skins: true, animation: true, polygons: true, vertexColors: true | `tests/model/x.luau` |
|
||||
| model | x3d | .x3d .x3dv .x3dz .x3dvz .x3db | yes | yes | materials: true, polygons: true, animation: true, cameras: true, lights: true, lines: true, points: true, xml: true, classic: true | `tests/model/x3d.luau` |
|
||||
| cad | step | .step .stp .p21 | yes | yes | complexEntities: true, sections: true, brep: "plugin", tessellate: "plugin" | `tests/cad/step.luau` |
|
||||
| font | bdf | .bdf | yes | yes | bitmap: true | `tests/font/bdf.luau` |
|
||||
| font | bmfont | .fnt | yes | yes | bitmap: true, variants: "text", "xml", "binary", extraFiles: true | `tests/font/bmfont.luau` |
|
||||
| font | eot | .eot | yes | yes | variants: "1.0", "2.1", "2.2" | `tests/font/eot.luau` |
|
||||
| font | fon | .fon .fnt | yes | - | bitmap: true, variants: "fnt2", "fnt3", "ne", "pe" | `tests/font/fon.luau` |
|
||||
| font | hershey | .jhf | yes | - | strokes: true | `tests/font/hershey.luau` |
|
||||
| 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" | `tests/font/type1.luau` |
|
||||
| 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 | cab | .cab | yes | yes | methods: "store", "mszip", "lzx", "quantum" | `tests/archive/cab.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 | grp | .grp | yes | yes | | `tests/archive/grp.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 | mpq | .mpq .w3x .w3m .sc2map .sc2data .s2ma .scm .scx | yes | - | versions: 1, 2, 3, 4, methods: "zlib", "implode", "bzip2", "lzma", "sparse", encryption: true | `tests/archive/mpq.luau` |
|
||||
| archive | pak | .pak .sin | yes | yes | variants: "quake", "sin" | `tests/archive/pak.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 | vpk | .vpk | yes | yes | versions: 1, 2, multipart: true | `tests/archive/vpk.luau` |
|
||||
| archive | wad | .wad | yes | yes | images: true, maps: true, variants: "iwad", "pwad" | `tests/archive/wad.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` |
|
||||
| data | cbor | .cbor | yes | yes | binary: true, ordered: true, tags: true | `tests/data/cbor.luau` |
|
||||
| data | csv | .csv .tsv | yes | yes | header: true | `tests/data/csv.luau` |
|
||||
@@ -187,15 +212,22 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
- codecs/compress/Deflate: DEFLATE (RFC 1951) decoder and compressor, with the zlib (RFC 1950) and gzip (RFC 1952) wrappers.
|
||||
- codecs/compress/Explode: decompressor for the PKWARE Data Compression Library "implode" format (DCL, 1987: MPQ
|
||||
- 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/Lzx: the LZX decoder as Microsoft Cabinet folders use it: windows of 2^15 .. 2^21 bytes,
|
||||
- codecs/compress/PackBits: the Apple PackBits run-length code (TIFF compression 32773, PSD / PSB RLE channels, IFF
|
||||
- codecs/compress/Quantum: the Quantum decoder (David Stafford's LZ77 with an adaptive arithmetic coder) as Microsoft
|
||||
- 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.
|
||||
- codecs/entropy/RangeCoder: the RFC 6716 range coder (libopus celt/entdec.c + entenc.c, BSD: licenses/libopus-BSD.txt):
|
||||
- **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/Bcn: the BCn block-compressed texture codecs, shared by the texture formats (DDS, KTX, VTF, BLP, ...):
|
||||
|
||||
+187
-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:
|
||||
|
||||
@@ -247,6 +248,168 @@ local script = assert(mpq:read("war3map.j")) -- zlib / PKWARE implo
|
||||
assert(buffer.len(script) == buffer.len(assert(mpq:read("readme.txt"))))
|
||||
local named = assert(F.archive.load(mpqBytes, { names = { "war3map.w3e" } }))
|
||||
assert(#named:list() >= 2)
|
||||
## 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")
|
||||
```
|
||||
|
||||
## LHA, ARJ and Zoo
|
||||
|
||||
DOS-era archives read with their own compressors (`codecs/compress/Lzh`): LHA / LZH at header levels 0 to 3 with
|
||||
lh0, lh1, lh4 to lh7, lhx and LArc's lzs / lz5 (Unix modes, symlinks, CRC-16 checked on `read`), ARJ methods 0 to 4
|
||||
(CRC-32 checked) and Zoo's stored, LZW and lzh entries (deleted entries skipped). LHA also writes (level 2 headers,
|
||||
stored data); ARJ and Zoo are read only.
|
||||
|
||||
```luau
|
||||
local lzh = assert(F.archive.load(lzhBytes))
|
||||
assert(lzh.format == "lha" and lzh:list()[1].method == "lh0") -- small files are stored
|
||||
assert(buffer.tostring(assert(lzh:read("readme.txt"))) == "formats-luau retro archives\n")
|
||||
local arj = assert(F.archive.load(arjBytes))
|
||||
assert(arj:read("src/main.c"))
|
||||
local zoo = assert(F.archive.load(zooBytes))
|
||||
assert(zoo:list()[1].method == "lzw" and zoo:read("readme.txt"))
|
||||
local stored = assert(F.save(lzh, nil, { format = "lha" })) -- level 2, lh0
|
||||
assert(F.archive.load(stored):list()[1].method == "lh0")
|
||||
```
|
||||
|
||||
## Encodings
|
||||
|
||||
Text and Mac encodings load as archives too: uuencode / xxencode / `begin-base64` blocks (`uu`), yEnc (multi-part
|
||||
postings in one text are joined), BinHex 4.0, MacBinary I / II / III and AppleSingle / AppleDouble. All of them read
|
||||
and write. Mac files keep the data fork as the entry `name` and a resource fork as `name .. ".rsrc"`
|
||||
(`fork = "resource"`), with `macType`, `macCreator` and `finderFlags`. A single-file encoding is a stream, so a
|
||||
uuencoded `.tar.gz` loads as the tar.
|
||||
|
||||
```luau
|
||||
local uu = assert(F.archive.load(uuText))
|
||||
assert(uu:list()[1].name == "readme.txt" and uu:list()[1].mode == 420) -- 420 = 0644
|
||||
local a = F.format("binhex").new()
|
||||
a:add("Read Me", "the data fork")
|
||||
a:add("Read Me.rsrc", "resources")
|
||||
a._byName["Read Me.rsrc"].fork = "resource"
|
||||
local hqx = assert(a:write())
|
||||
local back = assert(F.archive.load(hqx))
|
||||
assert(back:list()[2].fork == "resource" and buffer.tostring(back:read("Read Me")) == "the data fork")
|
||||
local y = assert(F.save(uu, nil, { format = "yenc" }))
|
||||
assert(string.sub(buffer.tostring(y), 1, 8) == "=ybegin ")
|
||||
```
|
||||
|
||||
## Disk images
|
||||
|
||||
Floppy and disk images list their files: Commodore D64 / D71 / D81 (PETSCII names as VICE's c1541 shows them,
|
||||
`type` = `prg` / `seq` / `usr` / `rel`, disk name and id in `meta`), Amiga ADF (OFS / FFS, international and
|
||||
directory-cache modes, protection bits, comments, links) and FAT12 / FAT16 / FAT32 images (VFAT long names; a
|
||||
hard-disk image opens its first FAT partition, `partition` picks another). D64 and FAT floppies also write.
|
||||
|
||||
```luau
|
||||
local d64 = assert(F.archive.load(d64Bytes))
|
||||
assert(d64.meta.disk == "games" and d64:list()[1].type == "prg")
|
||||
local adf = assert(F.archive.load(adfBytes))
|
||||
assert(adf.meta.volume == "Work" and adf.meta.fs == "ffs" and adf:read("s/readme"))
|
||||
local fat = assert(F.archive.load(floppyBytes))
|
||||
assert(fat.meta.fat == 12 and fat.meta.label == "DOCS" and fat:read("src/main.c"))
|
||||
local floppy = assert(F.save(adf, nil, { format = "fat", size = 720 })) -- copy the ADF's files to a FAT floppy
|
||||
assert(F.archive.load(floppy):read("s/readme"))
|
||||
```
|
||||
|
||||
## Microsoft Cabinet
|
||||
|
||||
Cabinet files (`.cab`) read with stored, MSZIP, LZX and Quantum folders; each data block's checksum is checked when
|
||||
a file of its folder is read. Entries carry the MS-DOS `attributes` (`readonly`, `executable`), `utf8` (the name flag)
|
||||
and `folder`; DOS times are local times without a zone, read as UTC. Files continued from or into another cabinet of
|
||||
a set read as `UNSUPPORTED`. Writing makes one folder, MSZIP (default, `level`) or stored (`compression = "none"`):
|
||||
|
||||
```luau
|
||||
local cab = assert(F.archive.load(cabBytes))
|
||||
assert(cab.format == "cab" and cab.meta.folders[1].method == "mszip")
|
||||
local by = {}
|
||||
for _, e in cab:list() do
|
||||
by[e.name] = e
|
||||
end
|
||||
assert(by["bin/tool.dll"].size == 16384 and by["readme.txt"].mtime == 1767225600)
|
||||
local out = assert(F.save(cab, nil, { format = "cab", compression = "none" }))
|
||||
assert(F.archive.load(out):list()[1].method == "store")
|
||||
```
|
||||
|
||||
## Formats
|
||||
@@ -266,6 +429,24 @@ assert(#named:list() >= 2)
|
||||
| GRP (`.grp`) | yes | yes | Build engine |
|
||||
| VPK (`.vpk`) | yes | yes | versions 1 / 2, multi-part reading, preload bytes; writes one directory file |
|
||||
| MPQ (`.mpq`, `.w3x`, `.sc2map`, ...) | yes | - | versions 1-4 (classic tables), encryption; no Huffman / ADPCM (WAVE) sectors |
|
||||
| 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 |
|
||||
| LHA (`.lzh`, `.lha`, `.lzs`) | yes | yes | levels 0-3; lh0 / lh1 / lh4-lh7 / lhx / lzs / lz5; writes stored level 2 |
|
||||
| ARJ (`.arj`) | yes | - | methods 0-4; no garbled entries, no multi-volume |
|
||||
| Zoo (`.zoo`) | yes | - | stored / LZW / lzh |
|
||||
| uuencode / xxencode (`.uu`, `.xxe`) | yes | yes | several blocks per text; GNU `begin-base64` too |
|
||||
| yEnc (`.yenc`) | yes | yes | multi-part postings in one text |
|
||||
| BinHex 4.0 (`.hqx`) | yes | yes | data and resource forks |
|
||||
| MacBinary (`.bin`) | yes | yes | I / II / III; writes III |
|
||||
| AppleSingle / AppleDouble | yes | yes | versions 1 and 2 |
|
||||
| C64 disks (`.d64`, `.d71`, `.d81`) | yes | yes | PETSCII names; no GEOS VLIR |
|
||||
| Amiga disks (`.adf`) | yes | - | OFS / FFS; no long-name (DOS 6 / 7) volumes |
|
||||
| FAT images (`.img`, `.ima`) | yes | yes | FAT12 / 16 / 32, VFAT names, MBR partitions; writes FAT12 floppies |
|
||||
| Cabinet (`.cab`) | yes | yes | stored / MSZIP / LZX / Quantum (read), stored / MSZIP (write); no spanned files |
|
||||
|
||||
Full capability list: [FORMATS.md](../FORMATS.md).
|
||||
|
||||
|
||||
+49
-1
@@ -232,6 +232,46 @@ local bm = assert(F.font.load(fnt, { loadPage = function(file) return pages[file
|
||||
assert(bm:rasterize(bm:glyphIndex(string.byte("H"))))
|
||||
```
|
||||
|
||||
## Bitmap fonts
|
||||
|
||||
BDF, PCF, PSF (Linux console) and Windows FNT / FON fonts load as the same Font, with their glyph bitmaps in
|
||||
`font.bitmap` (`size`, `ascent`, `descent`, `glyphs[i] = { codepoint, name, width, height, left, top, advance,
|
||||
pixels }`, one byte per pixel, 0 or 255). Units are pixels: `unitsPerEm` is the pixel size, `rasterize` returns the
|
||||
glyph as stored (its `px` argument only sets `img.meta.scale`), `outline` is nil. `.pcf.gz` and `.psfu.gz` load
|
||||
through the gzip. BDF and PSF also write, from any Font: a bitmap font as it is, an outline font rasterized at `px`.
|
||||
|
||||
```luau
|
||||
local bdf = assert(F.font.load(bdfText))
|
||||
assert(bdf.unitsPerEm == 8 and bdf.bitmap.glyphs[1].pixels)
|
||||
local g = bdf:rasterize(bdf:glyphIndex(65), 8)
|
||||
assert(g.format == "alpha8" and g.meta.advance == 5)
|
||||
local pcf = assert(F.font.load(pcfBytes))
|
||||
assert(pcf:glyphIndex(65) == bdf:glyphIndex(65))
|
||||
local psf = assert(F.font.load(psfBytes))
|
||||
assert(psf.meta.width == 8 and psf.meta.height == 16 and psf:glyphIndex(65) > 0)
|
||||
local fnt = assert(F.font.load(fntBytes))
|
||||
assert(fnt.unitsPerEm == 16)
|
||||
local console = assert(F.save(bdf, nil, { format = "psf" })) -- BDF -> PSF 2
|
||||
assert(F.font.load(console).meta.source.format == "psf")
|
||||
```
|
||||
|
||||
## Type 1, EOT and Hershey
|
||||
|
||||
PostScript Type 1 fonts (PFB and PFA) decrypt and run their charstrings into the same outlines as TrueType ones
|
||||
(glyph names map to Unicode through the Adobe Glyph List). EOT files unwrap the TrueType font inside (MTX-compressed
|
||||
ones are unsupported) and write. Hershey JHF fonts are stroke fonts: `outline` gives open paths (`meta.strokes`),
|
||||
`rasterize` strokes them.
|
||||
|
||||
```luau
|
||||
local t1 = assert(F.font.load(pfbBytes))
|
||||
assert(t1.unitsPerEm == 1000 and t1.info.family == "LMRoman10")
|
||||
assert(t1:rasterize(t1:glyphIndex(string.byte("g")), 32).width > 5)
|
||||
local eot = assert(F.font.load(eotBytes))
|
||||
assert(eot.meta.eot.familyName == "DejaVu Sans Mono" and eot:glyphIndex(65) > 0)
|
||||
local jhf = assert(F.font.load(jhfText))
|
||||
assert(jhf.meta.strokes and jhf:outline(1)[1].op == "moveTo")
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
@@ -240,13 +280,21 @@ assert(bm:rasterize(bm:glyphIndex(string.byte("H"))))
|
||||
| woff | yes | - | |
|
||||
| woff2 | yes | - | |
|
||||
| bmfont (`.fnt`) | yes | yes | text, XML and binary descriptors; `bake` from any outline font |
|
||||
| bdf (`.bdf`) | yes | yes | BDF 2.1; writes Unicode BDF from any font |
|
||||
| pcf (`.pcf`, `.pcf.gz`) | yes | - | every glyph pad / bit / byte order |
|
||||
| psf (`.psf`, `.psfu`) | yes | yes | PSF 1 / 2 with Unicode tables |
|
||||
| fon (`.fon`, `.fnt`) | yes | - | Windows raster FNT 2 / 3, NE / PE .fon with several sizes |
|
||||
| type1 (`.pfb`, `.pfa`) | yes | - | Type 1 charstrings (flex, seac), StandardEncoding / custom encodings |
|
||||
| eot (`.eot`) | yes | yes | EOT 1.0 / 2.1 / 2.2, XOR; no MTX |
|
||||
| hershey (`.jhf`) | yes | - | stroke fonts |
|
||||
|
||||
See [FORMATS.md](../FORMATS.md) for the capability matrix.
|
||||
|
||||
## Gotchas
|
||||
|
||||
- **No hinting, no shaping.** Glyphs are rendered from the outlines without hinting; there is no GSUB (ligatures,
|
||||
contextual forms), no variable fonts (CFF2 / gvar return `UNSUPPORTED`) and no colour or bitmap glyphs.
|
||||
contextual forms), no variable fonts (CFF2 / gvar return `UNSUPPORTED`) and no colour glyphs or embedded bitmap
|
||||
strikes in TrueType fonts (bitmap font formats are separate: see above).
|
||||
- **`px` is the em size**, not the line height. The line height is `(ascent - descent + lineGap) * px / unitsPerEm`.
|
||||
- **Units differ by kind.** Outline fonts measure in font units; BMFont in pixels at its baked size. Use
|
||||
`font.unitsPerEm` for both: for a BMFont, `px / unitsPerEm` is the scale relative to the baked size.
|
||||
|
||||
Reference in new issue
Block a user