]>
Commit | Line | Data |
---|---|---|
7cac9316 XL |
1 | # flate2 |
2 | ||
ea8adc8c XL |
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) | |
7cac9316 | 5 | |
60c5eb7d | 6 | A streaming compression/decompression library DEFALTE-based streams in Rust. |
7cac9316 | 7 | |
60c5eb7d XL |
8 | This crate by default implemented as a wrapper around the `miniz_oxide` crate, a |
9 | port of `miniz.c` to Rust. This crate can also optionally use the zlib library | |
10 | or `miniz.c` itself. | |
ff7c6d11 | 11 | |
7cac9316 XL |
12 | Supported formats: |
13 | ||
14 | * deflate | |
15 | * zlib | |
16 | * gzip | |
17 | ||
18 | ```toml | |
19 | # Cargo.toml | |
20 | [dependencies] | |
b7449926 | 21 | flate2 = "1.0" |
7cac9316 XL |
22 | ``` |
23 | ||
60c5eb7d | 24 | Using zlib instead of the Rust backend: |
7cac9316 XL |
25 | |
26 | ```toml | |
27 | [dependencies] | |
b7449926 | 28 | flate2 = { version = "1.0", features = ["zlib"], default-features = false } |
7cac9316 XL |
29 | ``` |
30 | ||
60c5eb7d | 31 | Using `miniz.c`: |
ff7c6d11 XL |
32 | |
33 | ```toml | |
34 | [dependencies] | |
60c5eb7d | 35 | flate2 = { version = "1.0", features = ["miniz-sys"], default-features = false } |
ff7c6d11 XL |
36 | ``` |
37 | ||
7cac9316 XL |
38 | ## Compression |
39 | ||
40 | ```rust | |
7cac9316 XL |
41 | use std::io::prelude::*; |
42 | use flate2::Compression; | |
43 | use flate2::write::ZlibEncoder; | |
44 | ||
45 | fn main() { | |
ff7c6d11 | 46 | let mut e = ZlibEncoder::new(Vec::new(), Compression::default()); |
b7449926 XL |
47 | e.write_all(b"foo"); |
48 | e.write_all(b"bar"); | |
7cac9316 XL |
49 | let compressed_bytes = e.finish(); |
50 | } | |
51 | ``` | |
52 | ||
53 | ## Decompression | |
54 | ||
55 | ```rust,no_run | |
7cac9316 XL |
56 | use std::io::prelude::*; |
57 | use flate2::read::GzDecoder; | |
58 | ||
59 | fn main() { | |
ff7c6d11 | 60 | let mut d = GzDecoder::new("...".as_bytes()); |
7cac9316 XL |
61 | let mut s = String::new(); |
62 | d.read_to_string(&mut s).unwrap(); | |
63 | println!("{}", s); | |
64 | } | |
65 | ``` | |
66 | ||
67 | # License | |
68 | ||
ff7c6d11 XL |
69 | This project is licensed under either of |
70 | ||
71 | * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or | |
72 | http://www.apache.org/licenses/LICENSE-2.0) | |
73 | * MIT license ([LICENSE-MIT](LICENSE-MIT) or | |
74 | http://opensource.org/licenses/MIT) | |
75 | ||
76 | at your option. | |
77 | ||
78 | ### Contribution | |
7cac9316 | 79 | |
ff7c6d11 XL |
80 | Unless you explicitly state otherwise, any contribution intentionally submitted |
81 | for inclusion in this project by you, as defined in the Apache-2.0 license, | |
82 | shall be dual licensed as above, without any additional terms or conditions. |