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