Find
C
ase-sensitive
R
egexp search
Path
comm-central
/
third_party
/
rust
/
flate2
/
src
Navigation
Enable keyboard shortcuts
Name
Description
Size
bufreader.rs
2814
crc.rs
Simple CRC bindings backed by miniz.c
4123
deflate
ffi
gz
lib.rs
A DEFLATE-based stream compression/decompression library This library provides support for compression and decompression of DEFLATE-based streams: * the DEFLATE format itself * the zlib format * gzip These three formats are all closely related and largely only differ in their headers/footers. This crate has three types in each submodule for dealing with these three formats. # Implementation In addition to supporting three formats, this crate supports several different backends, controlled through this crate's features: * `default`, or `rust_backend` - this implementation uses the `miniz_oxide` crate which is a port of `miniz.c` to Rust. This feature does not require a C compiler, and only uses safe Rust code. * `zlib-rs` - this implementation utilizes the `zlib-rs` crate, a Rust rewrite of zlib. This backend is the fastest, at the cost of some `unsafe` Rust code. Several backends implemented in C are also available. These are useful in case you are already using a specific C implementation and need the result of compression to be bit-identical. See the crate's README for details on the available C backends. The `zlib-rs` backend typically outperforms all the C implementations. # Organization This crate consists mainly of three modules, [`read`], [`write`], and [`bufread`]. Each module contains a number of types used to encode and decode various streams of data. All types in the [`write`] module work on instances of [`Write`][write], whereas all types in the [`read`] module work on instances of [`Read`][read] and [`bufread`] works with [`BufRead`][bufread]. If you are decoding directly from a `&[u8]`, use the [`bufread`] types. ``` use flate2::write::GzEncoder; use flate2::Compression; use std::io; use std::io::prelude::*; # fn main() { let _ = run(); } # fn run() -> io::Result<()> { let mut encoder = GzEncoder::new(Vec::new(), Compression::default()); encoder.write_all(b"Example")?; # Ok(()) # } ``` Other various types are provided at the top-level of the crate for management and dealing with encoders/decoders. Also note that types which operate over a specific trait often implement the mirroring trait as well. For example a `flate2::read::DeflateDecoder<T>` *also* implements the `Write` trait if `T: Write`. That is, the "dual trait" is forwarded directly to the underlying object if available. # About multi-member Gzip files While most `gzip` files one encounters will have a single *member* that can be read with the [`GzDecoder`], there may be some files which have multiple members. A [`GzDecoder`] will only read the first member of gzip data, which may unexpectedly provide partial results when a multi-member gzip file is encountered. `GzDecoder` is appropriate for data that is designed to be read as single members from a multi-member file. `bufread::GzDecoder` and `write::GzDecoder` also allow non-gzip data following gzip data to be handled. The [`MultiGzDecoder`] on the other hand will decode all members of a `gzip` file into one consecutive stream of bytes, which hides the underlying *members* entirely. If a file contains non-gzip data after the gzip data, MultiGzDecoder will emit an error after decoding the gzip data. This behavior matches the `gzip`, `gunzip`, and `zcat` command line tools. [`read`]: read/index.html [`bufread`]: bufread/index.html [`write`]: write/index.html [read]: https://doc.rust-lang.org/std/io/trait.Read.html [write]: https://doc.rust-lang.org/std/io/trait.Write.html [bufread]: https://doc.rust-lang.org/std/io/trait.BufRead.html [`GzDecoder`]: read/struct.GzDecoder.html [`MultiGzDecoder`]: read/struct.MultiGzDecoder.html
8797
mem.rs
30755
zio.rs
8105
zlib