zpack

package
v0.1.0-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Build(files map[string][]byte) []byte

Build encodes the named files as an archive. Entries with identical contents share one blob.

func Deflate

func Deflate(b []byte) []byte

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.

func Inflate

func Inflate(z string) []byte

Inflate decodes a blob made by Deflate. The embedded data is generated and tested, so corruption is a bug in the build, not a runtime condition: Inflate panics instead of returning an error nobody could act on.

func String

func String(z string) string

String is Inflate as a string.

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.

func Open

func Open(z string) (*Archive, error)

Open parses the index of an archive.

func (*Archive) Names

func (a *Archive) Names() []string

Names lists the entries in sorted order. The slice must not be modified.

func (*Archive) Read

func (a *Archive) Read(name string) ([]byte, bool)

Read returns a fresh copy of an entry's bytes.

func (*Archive) Size

func (a *Archive) Size(name string) (int, bool)

Size is the decoded length of an entry.

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.

func (*FS) Open

func (f *FS) Open(name string) (fs.File, error)

Open implements fs.FS.

func (*FS) ReadDir

func (f *FS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir implements fs.ReadDirFS.

func (*FS) ReadFile

func (f *FS) ReadFile(name string) ([]byte, error)

ReadFile implements fs.ReadFileFS without the extra copy Open+ReadAll would make.

type Lazy

type Lazy struct {
	// contains filtered or unexported fields
}

Lazy inflates a blob once and keeps the text. The zero value is ready; declare one per embedded blob:

//go:embed scope.js.z
var scopeZ string
var scope zpack.Lazy   // scope.Get(scopeZ)

func (*Lazy) Get

func (l *Lazy) Get(z string) string

Get returns the decoded text of z, inflating it on the first call (later calls must pass the same z).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL