This is the first milestone of a byte-exact rewrite of brotli (reference implementation tag v1.2.1) in Wuffs. The decoder mirrors c/dec/decode.c function by function, including its validation checks: the same output for valid input and the same verdict, with each BROTLI_DECODER_ERROR_FORMAT_* code mapped to a Wuffs status (see std/brotli/README.md). The C state machine is replaced by Wuffs coroutines, so decoding works with arbitrarily small src and dst buffers. The history window lives in the caller's workbuf. Huffman table groups, context maps and the static dictionary scratch space live in the decoder struct. The static dictionary, transforms, context lookup tables and prefix code tables in common_tables.wuffs are generated from the brotli source by script/print-brotli-tables.go. Tests: golden tests on the upstream tests/testdata vectors and on streams produced by the v1.2.1 CLI at several qualities and window sizes, 1-byte I/O limits, truncation at every prefix, malformed inputs per error code, trailing data and workbuf boundaries. With -mimic, every vector and every malformed input is also compared against libbrotlidec, including the exact error code. A differential run over about a million mutated inputs found no divergence. Not yet supported (left as TODOs): large-window brotli, custom/shared dictionaries, metadata callbacks and fast paths. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011NoosQNe7DKWnqDCBeqw1p
Standard Library
Wuffs' standard library consists of multiple packages, each implementing a particular file format or algorithm. Those packages can be grouped into several categories:
Other packages include std/softfloat, which implements bit-exact IEEE 754 floating point arithmetic using only integers.
The general pattern is that a package foo (e.g. jpeg, png) contains a
struct bar (e.g. hasher, decoder, etc) that implements a
package-independent interface. For example, every compression decoder struct
would have a transform_io method. In C, this would be invoked as
// Allocate and initialize the struct.
wuffs_foo__decoder* dec = etc;
// Do the work. Error checking is not shown, for brevity.
wuffs_base__status status = wuffs_foo__decoder__transform_io(dec, etc);
When that C library is used as C++, that last line can be shortened:
wuffs_base__status status = dec->transform_io(etc);
See also the glossary, as well as the notes on:
Modules and Dependencies
By default, building Wuffs' standard library builds the entire thing (provided
that you've defined the WUFFS_IMPLEMENTATION C macro), implementing a variety
of codecs and file formats.
Packages can be individually allow-listed, for smaller binaries and faster
compiles. Opt in by also defining WUFFS_CONFIG__MODULES and then also
WUFFS_CONFIG__MODULE__ETC for each ETC (and its dependencies, listed below)
to enable.
ADLER32: BASEBMP: BASEBZIP2: BASECBOR: BASECRC32: BASECRC64: BASEDEFLATE: BASEETC2: BASEGIF: BASEGZIP: BASE, CRC32, DEFLATEHANDSUM: BASEJPEG: BASEJSON: BASELZIP: BASE, CRC32, LZMALZMA: BASELZW: BASENETPBM: BASENIE: BASEPNG: BASE, ADLER32, CRC32, DEFLATE, ZLIBQOI: BASESHA256: BASESOFTFLOAT: BASETGA: BASETHUMBHASH: BASEVP8: BASEWBMP: BASEWEBP: BASE, VP8XXHASH32: BASEXXHASH64: BASEXZ: BASE, CRC32, CRC64, LZMA, SHA256ZLIB: BASE, ADLER32, DEFLATE
For the auxiliary modules:
AUX_CBOR: AUX_BASE, BASE, CBORAUX_IMAGE: AUX_BASE, BASEand whichever image-related modules (and their dependencies) you want, e.g.GIF,PNG, etc.AUX_JSON: AUX_BASE, BASE, JSON