flate2 1.0.13

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


Crates.io Documentation

A streaming compression/decompression library DEFLATE-based streams in Rust.

This crate by default implemented as a wrapper around the miniz_oxide crate, a port of miniz.c to Rust. This crate can also optionally use the zlib library or miniz.c itself.

Supported formats:

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

Using zlib instead of the Rust backend:

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

Using miniz.c:

flate2 = { version = "1.0", features = ["miniz-sys"], default-features = false }


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

fn main() {
    let mut e = ZlibEncoder::new(Vec::new(), Compression::default());
    let compressed_bytes = e.finish();


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);


This project is licensed under either of

at your option.


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.