deflate 0.7.13

A DEFLATE, zlib and gzip encoder written in rust.


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 to zlib and miniz.

So far, deflate encoding with and without zlib and gzip metadata (zlib dictionaryies are not supported yet) has been is implemented. At the moment there is only 1 line of unsafe code. Speed-wise it's not quite up to miniz-levels yet (between 10% and twice as slow for most files, for large uncompressible files it can be slower).


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

  • libflate Bindings to miniz.c that are part of the rust distribution.
  • flate2 FLATE, Gzip, and Zlib bindings for Rust
  • Zopfli in Rust Rust port of zopfli
  • inflate DEFLATE decoder implemented in rust
  • miniz-rs Direct rust translation of miniz.c
  • libflate (Not to be confused by libflate in the rust standard library) 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. is © @nwin and was released under both MIT and Apache 2.0

Some code in 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