]> git.proxmox.com Git - rustc.git/blob - vendor/flate2/README.md
New upstream version 1.63.0+dfsg1
[rustc.git] / vendor / flate2 / 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
6 A streaming compression/decompression library DEFLATE-based streams in Rust.
7
8 This crate by default uses the `miniz_oxide` crate, a port of `miniz.c` to pure
9 Rust. This crate also supports other [backends](#Backends), such as the widely
10 available zlib library or the high-performance zlib-ng library.
11
12 Supported formats:
13
14 * deflate
15 * zlib
16 * gzip
17
18 ```toml
19 # Cargo.toml
20 [dependencies]
21 flate2 = "1.0"
22 ```
23
24 ## Compression
25
26 ```rust
27 use std::io::prelude::*;
28 use flate2::Compression;
29 use flate2::write::ZlibEncoder;
30
31 fn main() {
32 let mut e = ZlibEncoder::new(Vec::new(), Compression::default());
33 e.write_all(b"foo");
34 e.write_all(b"bar");
35 let compressed_bytes = e.finish();
36 }
37 ```
38
39 ## Decompression
40
41 ```rust,no_run
42 use std::io::prelude::*;
43 use flate2::read::GzDecoder;
44
45 fn main() {
46 let mut d = GzDecoder::new("...".as_bytes());
47 let mut s = String::new();
48 d.read_to_string(&mut s).unwrap();
49 println!("{}", s);
50 }
51 ```
52
53 ## Backends
54
55 The default `miniz_oxide` backend has the advantage of being pure Rust. If you
56 want maximum performance, you can use the zlib-ng C library:
57
58 ```toml
59 [dependencies]
60 flate2 = { version = "1.0.17", features = ["zlib-ng"], default-features = false }
61 ```
62
63 Note that the `"zlib-ng"` feature works even if some other part of your crate
64 graph depends on zlib.
65
66 However, if you're already using another C or Rust library that depends on
67 zlib, and you want to avoid including both zlib and zlib-ng, you can use that
68 for Rust code as well:
69
70 ```toml
71 [dependencies]
72 flate2 = { version = "1.0.17", features = ["zlib"], default-features = false }
73 ```
74
75 Or, if you have C or Rust code that depends on zlib and you want to use zlib-ng
76 via libz-sys in zlib-compat mode, use:
77
78 ```toml
79 [dependencies]
80 flate2 = { version = "1.0.17", features = ["zlib-ng-compat"], default-features = false }
81 ```
82
83 Note that when using the `"zlib-ng-compat"` feature, if any crate in your
84 dependency graph explicitly requests stock zlib, or uses libz-sys directly
85 without `default-features = false`, you'll get stock zlib rather than zlib-ng.
86 See [the libz-sys
87 README](https://github.com/rust-lang/libz-sys/blob/main/README.md) for details.
88 To avoid that, use the `"zlib-ng"` feature instead.
89
90 For compatibility with previous versions of `flate2`, the Cloudflare optimized
91 version of zlib is available, via the `cloudflare_zlib` feature. It's not as
92 fast as zlib-ng, but it's faster than stock zlib. It requires an x86-64 CPU with
93 SSE 4.2 or ARM64 with NEON & CRC. It does not support 32-bit CPUs at all and is
94 incompatible with mingw. For more information check the [crate
95 documentation](https://crates.io/crates/cloudflare-zlib-sys). Note that
96 `cloudflare_zlib` will cause breakage if any other crate in your crate graph
97 uses another version of zlib/libz.
98
99 # License
100
101 This project is licensed under either of
102
103 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
104 https://www.apache.org/licenses/LICENSE-2.0)
105 * MIT license ([LICENSE-MIT](LICENSE-MIT) or
106 https://opensource.org/licenses/MIT)
107
108 at your option.
109
110 ### Contribution
111
112 Unless you explicitly state otherwise, any contribution intentionally submitted
113 for inclusion in this project by you, as defined in the Apache-2.0 license,
114 shall be dual licensed as above, without any additional terms or conditions.