#flate #deflate #zlib #compression #gzip


A DEFLATE, zlib and gzip encoder written in rust

26 releases

0.8.6 Jul 6, 2020
0.8.4 Apr 4, 2020
0.8.3 Feb 4, 2020
0.8.2 Nov 8, 2019
0.6.0 Nov 24, 2016

#8 in Compression

Download history 26134/week @ 2020-04-13 25509/week @ 2020-04-20 27063/week @ 2020-04-27 28298/week @ 2020-05-04 32366/week @ 2020-05-11 30864/week @ 2020-05-18 35306/week @ 2020-05-25 30192/week @ 2020-06-01 35040/week @ 2020-06-08 33568/week @ 2020-06-15 30992/week @ 2020-06-22 31948/week @ 2020-06-29 33466/week @ 2020-07-06 34692/week @ 2020-07-13 35747/week @ 2020-07-20 31923/week @ 2020-07-27

129,124 downloads per month
Used in 27 crates (13 directly)


4.5K SLoC


Build StatusCrates.ioDocs

An implementation of a DEFLATE encoder in pure Rust. Not a direct port, but does take some inspiration from zlib, miniz and zopfli. The API is based on the one in the flate2 crate that contains bindings, zlib miniz_oxide, and miniz.

Deflate encoding with and without zlib and gzip metadata (zlib dictionaries are not supported) is supported. No unsafe code is used.

This library is now mostly in maintenance mode, focus being on the Rust backend of flate2 instead.


Simple compression function:

use deflate::deflate_bytes;

let data = b"Some data";
let compressed = deflate_bytes(&data);

Using a writer:

use std::io::Write;

use deflate::Compression;
use deflate::write::ZlibEncoder;

let data = b"This is some test data";
let mut encoder = ZlibEncoder::new(Vec::new(), Compression::Default);
let compressed_data = encoder.finish().unwrap();

Other deflate/zlib Rust projects from various people

  • flate2 FLATE, Gzip, and Zlib bindings for Rust - can use miniz_oxide for a pure Rust implementation.
  • Zopfli in Rust Rust port of zopfli
  • inflate DEFLATE decoder implemented in Rust
  • miniz-oxide Port of miniz to Rust.
  • libflate Another DEFLATE/Zlib/Gzip encoder and decoder written in Rust. (Only does some very light compression).


deflate is distributed under the terms of both the MIT and Apache 2.0 licences.

bitstream.rs is © @nwin and was released under both MIT and Apache 2.0

Some code in length_encode.rs has been ported from the miniz library, which is public domain.

The test data (src/pg11.txt) is borrowed from Project Gutenberg and is available under public domain, or the Project Gutenberg Licence