rust-brotli

A no-std-friendly Rust port of Google's Brotli compressor and decompressor, byte-compatible with the reference C implementation.

Library
Cargo
v9.0.0
943stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
73/100Good
Development Activity68
Maintenance60
Community76
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
68/100Good
Architecture78
Code Quality68
Innovation72
Learning Curve55

rust-brotli is a from-scratch Rust implementation of the Brotli compression algorithm, built to be a drop-in replacement for Google’s C brotli library at compression levels 0-11. It ships both a compressor and decompressor with io::Read and io::Write wrapper types for idiomatic streaming usage, plus a lower-level manual-memory-management API for no_std environments such as embedded devices, kernels, or sandboxed workers where the caller supplies its own allocator.

Beyond core compression, the crate implements Brotli stream concatenation (both a fast bare-byte mode and a size-optimized catbrotli tool), multithreaded compression via a worker pool, an FFI layer for linking from C code in place of libbrotli.so, and a validation mode that double-checks a compressed stream can be decompressed with the same settings. It is maintained by Dropbox and is a common dependency wherever Rust projects need Brotli support without pulling in the full C toolchain.

What You Get

  • Read/Write stream wrappers - CompressorReader/Compressor and Decompressor/DecompressorWriter types that implement io::Read and io::Write for drop-in streaming compression and decompression.
  • no_std manual memory management API - a three-step BrotliState + BrotliDecompressStream loop for environments without the Rust standard library, with pluggable custom allocators.
  • C-compatible FFI layer - an ffi-api feature exposing a C ABI that can replace libbrotli.so directly, including custom allocator support and panic-safe boundaries via catch_unwind.
  • Stream concatenation tooling - both a zero-processing bare-byte concatenation mode and a catbrotli binary for size-optimized concatenation of independently compressed chunks.
  • Multithreaded compression - a worker-pool based CompressMulti path for compressing large inputs across multiple threads.
  • Bit-identical compatibility - compression levels 0-9 produce byte-identical output to the reference C brotli implementation, useful for cross-language interop and reproducible builds.

Common Use Cases

  • Embedding Brotli in no_std binaries - firmware, kernels, or sandboxed (e.g. seccomp-jailed) processes that need compression without a syscall-capable allocator.
  • Replacing a system libbrotli dependency - projects that want a memory-safe Rust implementation behind the same C FFI surface as Google’s reference library.
  • HTTP body compression - Rust web servers and clients streaming Brotli-encoded request/response bodies via the io::Read/io::Write wrappers.
  • Chunked/streaming compression pipelines - systems (like Dropbox’s own Broccoli sync engine) that compress data incrementally and concatenate the resulting streams later.
  • Cross-implementation fuzzing and validation - using the crate’s validation mode to confirm compressed output decompresses correctly before shipping it.

Under The Hood

Architecture The crate splits along the compress/decompress boundary: src/enc/ holds the encoder (encode.rs, metablock.rs, block_splitter.rs, entropy_encode.rs, static_dict.rs) organized around a metablock-at-a-time pipeline of LZ77 backward-reference search, block splitting, and entropy coding, while decompression is re-exported from the separate brotli-decompressor crate. An ffi/ module (gated by the ffi-api feature) wraps both directions behind a C ABI in compressor.rs/decompressor.rs/broccoli.rs, with catch_unwind boundaries so Rust panics don’t unwind across extern "C". A concat/ module implements the BroCatli stream-concatenation state machine. The crate is #![no_std] at the root, with a std feature that layers io::Read/io::Write wrappers and the default heap allocator (alloc-stdlib) on top of the no_std core; every allocation-touching type is generic over an Allocator trait, so callers can supply stack, pool, or custom allocators without recompiling internals. Tech Stack Pure Rust, edition 2015, MSRV 1.59.0, built with cargo. Runtime dependencies are minimal and deliberately no_std-first: alloc-no-stdlib for the allocator trait, alloc-stdlib (optional, std feature) for a heap-backed allocator, brotli-decompressor (a sibling crate under the same repo/org) for the decompression path, and an optional sha2 dependency gated behind a validation feature. Optional Cargo features (ffi-api, simd, benchmark, seccomp, portable-float) toggle nightly-only or platform-specific code paths, keeping the default build stable-Rust and dependency-light. CI covers Travis (Linux) and AppVeyor (Windows, both MSVC and GNU targets, 32- and 64-bit), and a c/ subdirectory with its own make-based build produces a libbrotli.so for C consumers. Code Quality Tests exist as #[test]-annotated unit tests embedded in source (e.g. src/enc/test.rs) rather than a separate tests/ integration directory, exercising encoder correctness against known inputs; there’s also a src/bin/integration_tests.rs and validate.rs binary for end-to-end round-trip and cross-implementation checks. Error handling favors explicit Result/status-enum returns (e.g. BrotliFileNotCraftedForConcatenation, Result<BroCatli, ()>) over panics on malformed input, with recent changelog entries specifically hardening against integer-underflow and NULL-pointer panics at FFI boundaries. Naming follows the original C brotli API closely (non-idiomatic Rust casing is explicitly allowed via #![allow(non_snake_case)]), which trades Rust-idiom polish for close parity with the reference implementation and easier porting of fixes between the two. What Makes It Unique Unlike bindings that FFI into Google’s C brotli, this is an independent from-scratch Rust port that stays bit-identical to the C encoder at levels 0-9 while adding capabilities the reference implementation doesn’t expose as directly: a fully allocator-pluggable no_std core suitable for kernels and seccomp-jailed processes, multithreaded compression via a worker pool, and a stream-concatenation feature (BroCatli/Broccoli) built specifically to support incremental, chunked compression workloads like Dropbox’s own sync infrastructure.

Used by 5 apps in this directory

Rust
100%
Other

Meilisearch

Search

59,291

Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.

View details
90
Repo Health
88
Technical
68
Dependency
Built with
Rust100%
Updated 3 days ago
Python
54%
Other

PostHog

Analytics · Monitoring · Developer Tools

39,797

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python54%
TypeScript36%
Updated 2 days ago
Java
92%
Apache 2.0

QuestDB

Databases · Analytics

17,321

A high-performance, open-source time-series database built for financial market data, IoT telemetry, and real-time analytics, combining a zero-GC Java/C++ core with SIMD-accelerated SQL and a WAL-to-Parquet storage engine.

View details
91
Repo Health
86
Technical
68
Dependency
Built with
Java92%
Updated 3 days ago
Rust
70%
AGPL 3.0

RustDesk

Networking

123,529

Open-source, self-hosted remote desktop built in Rust — your data, your infrastructure, no third-party cloud.

View details
93
Repo Health
84
Technical
71
Dependency
Built with
Rust70%
Dart22%
Updated 3 days ago
Apache 2.0

TensorZero

AI Development · Ab Testing Experimentation · Monitoring

11,719

TensorZero unifies the LLM gateway, observability, evaluation, optimization, and experimentation stack behind a single OpenAI-compatible API, built in Rust for sub-millisecond p99 latency.

View details
54
Repo Health
87
Technical
0
Dependency

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search