#zlib #gzip #flate

deflate

A DEFLATE, zlib and gzip encoder written in Rust

29 releases (1 stable)

1.0.0 Nov 10, 2021
0.9.1 Mar 24, 2021
0.9.0 Jan 21, 2021
0.8.6 Jul 6, 2020
0.6.0 Nov 24, 2016

#13 in Compression

Download history 27332/week @ 2023-12-24 47866/week @ 2023-12-31 63711/week @ 2024-01-07 60756/week @ 2024-01-14 66173/week @ 2024-01-21 66660/week @ 2024-01-28 58995/week @ 2024-02-04 76315/week @ 2024-02-11 68485/week @ 2024-02-18 65164/week @ 2024-02-25 51172/week @ 2024-03-03 52378/week @ 2024-03-10 53659/week @ 2024-03-17 60915/week @ 2024-03-24 57691/week @ 2024-03-31 35868/week @ 2024-04-07

211,375 downloads per month
Used in 98 crates (38 directly)

MIT/Apache

240KB
4.5K SLoC

deflate-rs

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.

Encoding in gzip format requires enabling the 'gzip' feature.

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

The minimum required Rust version is 1.32.0 due to use of library functions for endinaness conversion (unit tests requires a newer version).

Usage:

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);
encoder.write_all(data).unwrap();
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).

License

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 (tests/pg11.txt) is borrowed from Project Gutenberg and is available under public domain, or the Project Gutenberg Licence

Dependencies