• Home
Name Date Size #Lines LOC

..--

examples/04-Jul-2025-493373

patches/04-Jul-2025-4539

src/04-Jul-2025-6,7163,986

tests/04-Jul-2025-920890

.android-checksum.jsonD04-Jul-20256 KiB11

.cargo-checksum.jsonD04-Jul-20255.5 KiB11

Android.bpD04-Jul-20253.8 KiB183174

CHANGELOG.mdD04-Jul-2025121.1 KiB1,9211,422

Cargo.lockD04-Jul-20254.9 KiB199175

Cargo.tomlD04-Jul-20254.7 KiB244203

LICENSED04-Jul-202510.6 KiB202169

LICENSE-APACHED04-Jul-202510.6 KiB202169

MAINTENANCE.mdD04-Jul-20251.3 KiB2920

METADATAD04-Jul-2025514 1817

MODULE_LICENSE_APACHE2D04-Jul-20250

README.mdD04-Jul-20254.2 KiB13096

TEST_MAPPINGD04-Jul-20251.3 KiB6463

cargo_embargo.jsonD04-Jul-2025496 2626

README.md

1# flate2
2
3[![Crates.io](https://img.shields.io/crates/v/flate2.svg?maxAge=2592000)](https://crates.io/crates/flate2)
4[![Documentation](https://docs.rs/flate2/badge.svg)](https://docs.rs/flate2)
5
6A streaming compression/decompression library DEFLATE-based streams in Rust.
7
8This crate by default uses the `miniz_oxide` crate, a port of `miniz.c` to pure
9Rust. This crate also supports other [backends](#backends), such as the widely
10available zlib library or the high-performance zlib-ng library.
11
12Supported formats:
13
14* deflate
15* zlib
16* gzip
17
18```toml
19# Cargo.toml
20[dependencies]
21flate2 = "1.0"
22```
23
24## MSRV (Minimum Supported Rust Version) Policy
25
26This crate supports the current and previous stable versions of the Rust compiler.
27For example, if the current stable is 1.80, this crate supports 1.80 and 1.79.
28
29Other compiler versions may work, but failures may not be treated as a `flate2` bug.
30
31The `Cargo.toml` file specifies a `rust-version` for which builds of the current version
32passed at some point. This value is indicative only, and may change at any time.
33
34The `rust-version` is a best-effort measured value and is different to the MSRV. The
35`rust-version` can be incremented by a PR in order to pass tests, as long as the MSRV
36continues to hold. When the `rust-version` increases, the next release should be a minor
37version, to allow any affected users to pin to a previous minor version.
38
39## Compression
40
41```rust
42use std::io::prelude::*;
43use flate2::Compression;
44use flate2::write::ZlibEncoder;
45
46fn main() {
47    let mut e = ZlibEncoder::new(Vec::new(), Compression::default());
48    e.write_all(b"foo");
49    e.write_all(b"bar");
50    let compressed_bytes = e.finish();
51}
52```
53
54## Decompression
55
56```rust,no_run
57use std::io::prelude::*;
58use flate2::read::GzDecoder;
59
60fn main() {
61    let mut d = GzDecoder::new("...".as_bytes());
62    let mut s = String::new();
63    d.read_to_string(&mut s).unwrap();
64    println!("{}", s);
65}
66```
67
68## Backends
69
70The default `miniz_oxide` backend has the advantage of being pure Rust. If you
71want maximum performance, you can use the zlib-ng C library:
72
73```toml
74[dependencies]
75flate2 = { version = "1.0.17", features = ["zlib-ng"], default-features = false }
76```
77
78Note that the `"zlib-ng"` feature works even if some other part of your crate
79graph depends on zlib.
80
81However, if you're already using another C or Rust library that depends on
82zlib, and you want to avoid including both zlib and zlib-ng, you can use that
83for Rust code as well:
84
85```toml
86[dependencies]
87flate2 = { version = "1.0.17", features = ["zlib"], default-features = false }
88```
89
90Or, if you have C or Rust code that depends on zlib and you want to use zlib-ng
91via libz-sys in zlib-compat mode, use:
92
93```toml
94[dependencies]
95flate2 = { version = "1.0.17", features = ["zlib-ng-compat"], default-features = false }
96```
97
98Note that when using the `"zlib-ng-compat"` feature, if any crate in your
99dependency graph explicitly requests stock zlib, or uses libz-sys directly
100without `default-features = false`, you'll get stock zlib rather than zlib-ng.
101See [the libz-sys
102README](https://github.com/rust-lang/libz-sys/blob/main/README.md) for details.
103To avoid that, use the `"zlib-ng"` feature instead.
104
105For compatibility with previous versions of `flate2`, the Cloudflare optimized
106version of zlib is available, via the `cloudflare_zlib` feature. It's not as
107fast as zlib-ng, but it's faster than stock zlib. It requires an x86-64 CPU with
108SSE 4.2 or ARM64 with NEON & CRC. It does not support 32-bit CPUs at all and is
109incompatible with mingw. For more information check the [crate
110documentation](https://crates.io/crates/cloudflare-zlib-sys). Note that
111`cloudflare_zlib` will cause breakage if any other crate in your crate graph
112uses another version of zlib/libz.
113
114# License
115
116This project is licensed under either of
117
118 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
119   https://www.apache.org/licenses/LICENSE-2.0)
120 * MIT license ([LICENSE-MIT](LICENSE-MIT) or
121   https://opensource.org/licenses/MIT)
122
123at your option.
124
125### Contribution
126
127Unless you explicitly state otherwise, any contribution intentionally submitted
128for inclusion in this project by you, as defined in the Apache-2.0 license,
129shall be dual licensed as above, without any additional terms or conditions.
130