gecko-dev/third_party/rust/flate2
Jan-Erik Rediger 4d415be57c Bug 1640927 - Upgrade glean-core to v31.0.2 r=chutten
This gets us default gzip compression on ping sending.

Differential Revision: https://phabricator.services.mozilla.com/D77455
2020-05-29 13:47:18 +00:00
..
examples
src
tests
.cargo-checksum.json
Cargo.lock
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
README.md

README.md

flate2

Crates.io Documentation

A streaming compression/decompression library DEFALTE-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
[dependencies]
flate2 = "1.0"

Using zlib instead of the Rust backend:

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

Using miniz.c:

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

Compression

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

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.