Skip to content
baskingspotPublic

About

Compression codecs in pure Zig: Snappy, DEFLATE, gzip, zlib, Zstandard, and Brotli.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

compress

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.

Bar chart of one-shot throughput on 64 KiB inputs, median across eight corpus shapes and seven EC2 targets: snappy encodes at 18 GB/s and decodes at 9, zstd at 5 and 12, brotli at 0.1 and 10.

What is in it

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.

Install

zig fetch --save https://baskingspot.dev/compress/v0.2.0.tar.gz

Add 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.

Documentation

  • 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/.

Work on it

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 demo

just 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.

License

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.

How it's made

Built with LLM assistance. How, in detail.

baskingspot

About

Compression codecs in pure Zig: Snappy, DEFLATE, gzip, zlib, Zstandard, and Brotli.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages