miniz_oxide
Pure-Rust DEFLATE, zlib, and gzip compression and decompression with no unsafe code and no_std support.
Repository Health
Technical Analysis
miniz_oxide is a pure-Rust reimplementation of the popular miniz C library, providing DEFLATE compression and decompression (and the zlib/gzip wrappers built on it) with no unsafe code. It builds in no_std mode and is designed as a safe, portable backend for higher-level streaming libraries.
It is most widely known as the Rust-only backend for flate2, and through that path underpins a huge share of the Rust ecosystem’s compression needs — reflected in its hundreds of millions of downloads. It exposes both a low-level core API and an optional C API shell that mirrors miniz/zlib.
What You Get
- Pure-Rust DEFLATE compression and decompression with no unsafe code
- zlib and gzip stream wrappers on top of the raw DEFLATE core
- no_std support using alloc or preallocated memory slices
- A low-level API used as the backend for flate2 and similar crates
- An optional C API shell replicating the miniz/zlib interface
Common Use Cases
- Serving as the Rust-only DEFLATE backend behind flate2’s readers and writers
- Compressing and decompressing zlib/gzip data in Rust applications
- Running compression in no_std or embedded contexts without C dependencies
- Replacing miniz/zlib C code with a memory-safe equivalent via the C API
Under The Hood
Architecture - The Rust crate lives in the miniz_oxide/ subdirectory of a larger repo that also hosts a C API shell (miniz_oxide_c_api) and vendored miniz sources. Its src splits into deflate/ (the encoder), inflate/ (the decoder), a shared.rs of common tables and constants, and an optional serde module. The public functions operate on byte slices and a compressor/decompressor state, with the streaming ergonomics left to consumers like flate2.
Tech Stack - Written in Rust (edition 2021) with a deliberately tiny dependency set: adler2 for checksums, optional simd-adler32 for SIMD acceleration, and optional serde. Special rustc-std-workspace-core/alloc features let it be built as part of the Rust standard library. The C header is generated with cbindgen.
Code Quality - The project emphasizes safety (no unsafe code) and is thoroughly exercised with a tests/ directory, a separate miniz_oxide_test crate, fuzz targets under fuzz/, and benchmarks, plus scripts that compare behavior against the original C miniz. A CHANGELOG documents a notable past performance regression and its fix.
API Design - The core API is lower-level (buffer-oriented compress/decompress calls and state objects) rather than a friendly streaming interface, which is why most users reach it indirectly through flate2. Documentation is on docs.rs; direct use has a steeper learning curve, but the C API offers a familiar zlib-shaped surface for migration.