Compression codecs in pure Zig: Snappy, DEFLATE, gzip, zlib, Zstandard, and Brotli.
compress is one Zig module with a namespace per codec. The caller owns
every buffer, and the default APIs do not allocate: zstd's streaming
*Alloc variants are the opt-in that takes an allocator, for buffers too
large for a stack. Streaming goes through std.Io. The module imports only
std and fastmem.
| Namespace | Format | Support |
|---|---|---|
snappy |
Snappy blocks | encode, decode, streaming |
flate |
raw DEFLATE, RFC 1951 | encode, decode, streaming, preset dictionary |
gzip |
gzip, RFC 1952, over flate |
encode, decode, streaming |
zlib |
zlib, RFC 1950, over flate |
encode, decode, streaming, preset dictionary |
zstd |
Zstandard, RFC 8878 | encode (levels 1, 3), decode, streaming, dictionaries |
brotli |
Brotli, RFC 7932 | encode (quality 3), decode, streaming |
Not implemented:
- A zstd dictionary trainer: the zstd CLI trains dictionaries, and this package consumes them.
zig fetch --save https://baskingspot.dev/compress/v0.2.0.tar.gzAdd the module to your build:
const compress = b.dependency("compress", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("compress", compress.module("compress"));Then import a codec:
const gzip = @import("compress").gzip;std has a std.compress of its own. In a file that uses both, bind this module as compressx.
compress builds with Zig 0.16 only.
- The guide says which codec to use for a task, with examples that compile.
- The API reference documents every symbol.
examples/has a command-line tool for each codec.- Each codec's README documents its API, error sets, and buffer sizes. The specs are vendored in
docs/specs/.
nix develop # Zig 0.16, zls, ziglint, zigdoc, and the rest
just ci # unit tests, lint, and the cross-target compile gate
just fuzz # fuzz every codec's targets, 10M iterations each by default
just bench # local benchmarks
just wasm-demo # build and serve the browser demojust lists every recipe. Numbers from just bench are local and are not claims. Comparisons with other libraries are measured on EC2 by the harness in bench/, which describes the grid and the method.
MIT. See LICENSE. Ports and vendored artifacts are listed in THIRD_PARTY.md. The logo files in docs/static/ are baskingspot marks and are not covered by it. See docs/static/LICENSE.
Built with LLM assistance. How, in detail.