Brotli.zig - Native Brotli Compression Library for Zig

brotli.zig

brotli.zig is a native Brotli implementation for Zig.

The project is a complete implementation of the Brotli compressed-data format (RFC 7932, including the Large Window extension), built entirely from scratch in pure Zig.

There are no C bindings, no libc dependency, and no external dependencies. The upstream Brotli project is used as a reference for format behavior, compatibility, and interoperability testing.

The implementation currently supports:

  • Brotli compression and decompression

  • Streaming compression and decompression

  • Huffman encoding and decoding

  • LZ77 back-references with ring-buffer history

  • Context modeling and context maps

  • Complete RFC 7932 static dictionary with 121 transforms

  • Custom dictionaries

  • Shared and compound dictionaries

  • Compression quality levels 0–11

  • Large Window Brotli

  • Reusable compression and decompression contexts

  • Progress callbacks for streaming compression

  • Resource limits for decompression

  • UTF-8 heuristic modeling

  • Generic, text, and font compression modes

  • Format introspection and detailed error handling

The library is designed to feel natural in Zig, with explicit allocator usage, reusable codec contexts, and APIs built around Zig’s std.Io.Reader and std.Io.Writer.

Project: GitHub - muhammad-fiaz/brotli.zig
Documentation: brotli.zig | Native Zig Compression Library

Supported Zig versions

  • Zig 0.17.0

  • Zig 0.16.0

Why a Native Brotli Implementation?

This project originally started as C bindings to the Brotli implementation, but I wanted to move away from that approach and build the implementation natively in Zig. Zig currently does not provide native Brotli support, so I decided to implement it directly in Zig.

Building the implementation directly in Zig gives me control over memory allocation, codec state, streaming, dictionaries, and the public API, while keeping the library free from C bindings and external runtime dependencies.

The library is designed to support all targets supported by Zig, making it suitable for cross-platform and cross-compilation use.

AI / LLM usage disclosure

I used AI/LLM tools minimally during development, mainly for occasional code assistance, debugging, and documentation.

The project was not purely vibe coded. I designed and implemented the architecture and core functionality myself, and reviewed and tested the changes throughout development.

I’d really appreciate any feedback, suggestions, or ideas from the Zig community. If you have thoughts on the API, implementation, compatibility, performance, or anything that could be improved, I’d love to hear them.

Similar projects

2 Likes