]> git.proxmox.com Git - rustc.git/blob - src/vendor/flate2/examples/gzbuilder.rs
New upstream version 1.31.0+dfsg1
[rustc.git] / src / vendor / flate2 / examples / gzbuilder.rs
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()
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 }