#gzip #flate #zlib #encoding

flate2

Bindings to miniz.c for DEFLATE compression and decompression exposed as Reader/Writer streams. Contains bindings for zlib, deflate, and gzip-based streams.

36 releases (3 stable)

1.0.2 Jul 31, 2018
1.0.1 Nov 30, 2017
0.2.20 Sep 15, 2017
0.2.19 Apr 12, 2017
0.1.0 Nov 27, 2014

#1 in Compression

Download history 18929/week @ 2018-05-10 22400/week @ 2018-05-17 20883/week @ 2018-05-24 21292/week @ 2018-05-31 22951/week @ 2018-06-07 20365/week @ 2018-06-14 20846/week @ 2018-06-21 20859/week @ 2018-06-28 21550/week @ 2018-07-05 22294/week @ 2018-07-12 23573/week @ 2018-07-19 22020/week @ 2018-07-26 22067/week @ 2018-08-02

93,340 downloads per month
Used in 361 crates (183 directly)

MIT/Apache

491KB
9K SLoC

C 6K SLoC // 0.1% comments Rust 3.5K SLoC // 0.3% comments

flate2

Build Status Build status Crates.io Documentation

A streaming compression/decompression library for Rust. The underlying implementation by default uses miniz but can optionally be configured to use the system zlib, if available.

There is also an experimental rust backend that uses the miniz_oxide crate. This avoids the need to build C code, but hasn't gone through as much testing as the other backends.

Supported formats:

  • deflate
  • zlib
  • gzip
# Cargo.toml
[dependencies]
flate2 = "1.0"

Using zlib instead of miniz:

[dependencies]
flate2 = { version = "1.0", features = ["zlib"], default-features = false }

Using the rust back-end:

[dependencies]
flate2 = { version = "1.0", features = ["rust_backend"], default-features = false }

Compression

extern crate flate2;

use std::io::prelude::*;
use flate2::Compression;
use flate2::write::ZlibEncoder;

fn main() {
    let mut e = ZlibEncoder::new(Vec::new(), Compression::default());
    e.write_all(b"foo");
    e.write_all(b"bar");
    let compressed_bytes = e.finish();
}

Decompression

extern crate flate2;

use std::io::prelude::*;
use flate2::read::GzDecoder;

fn main() {
    let mut d = GzDecoder::new("...".as_bytes());
    let mut s = String::new();
    d.read_to_string(&mut s).unwrap();
    println!("{}", s);
}

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1MB
~21K SLoC