]>
Commit | Line | Data |
---|---|---|
ea8adc8c XL |
1 | extern crate flate2; |
2 | ||
3 | use std::io::prelude::*; | |
4 | use std::io; | |
5 | use std::fs::File; | |
6 | use flate2::GzBuilder; | |
7 | use flate2::Compression; | |
8 | ||
9 | // Open file and debug print the contents compressed with gzip | |
10 | fn main() { | |
11 | sample_builder().unwrap(); | |
12 | } | |
13 | ||
14 | // GzBuilder opens a file and writes a sample string using Builder pattern | |
15 | fn sample_builder() -> Result<(), io::Error> { | |
16 | let f = File::create("examples/hello_world.gz")?; | |
17 | let mut gz = GzBuilder::new() | |
b7449926 XL |
18 | .filename("hello_world.txt") |
19 | .comment("test file, please delete") | |
20 | .write(f, Compression::default()); | |
21 | gz.write_all(b"hello world")?; | |
ea8adc8c XL |
22 | gz.finish()?; |
23 | Ok(()) | |
24 | } |