Documentation
¶
Overview ¶
Package zpack holds the compact form of the data that travels inside the Sweef binary: JavaScript preludes, the chrome UI assets, the IANA time zone database. Text compresses to a quarter of its size, and the binary has a size budget (docs/development.md, "Binary size budget"), so these are embedded deflated and inflated on first use.
Two shapes exist:
- a blob: one raw DEFLATE stream (RFC 1951, compress/flate), file name "<source>.z" next to its source. Inflate and String decode it. The sources are not embedded, only the .z files are.
- an archive ("ZAR1"): many named blobs behind an index, with identical contents stored once (the time zone database has hundreds of aliases). Open parses the index without copying; Archive.Read inflates one entry.
Archive layout, all integers unsigned LEB128 (encoding/binary Uvarint):
"ZAR1" nBlobs, then per blob: rawLen, storedLen (storedLen == rawLen: the bytes are stored, not deflated) nEntries, then per entry: nameLen, name, blobIndex the blobs' bytes, concatenated in blob order
Entries are sorted by name. The generator is tools/zpack; each consumer has a test that decodes everything and compares it with the source files, so a stale .z/.zar file fails the build's tests instead of shipping.
Only the read side is reachable from the browser: the writer (build.go) is dead code in the binary and is removed by the linker.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build encodes the named files as an archive. Entries with identical contents share one blob.
func Deflate ¶
Deflate encodes b as a blob. The result is never longer than a stored encoding would be plus a few bytes, and for empty input it is the 2-byte empty stream.
Types ¶
type Archive ¶
type Archive struct {
// contains filtered or unexported fields
}
Archive is a parsed archive. The names and blobs alias the string it was opened from.
type FS ¶
type FS struct {
Z string // the archive, as embedded
// contains filtered or unexported fields
}
FS serves the entries of an archive as a read-only file system, inflating a file when it is opened. Files implement io.Seeker and io.ReaderAt, so net/http.FS can serve them. It behaves like embed.FS: no modification times, regular files 0444, directories 0555.