]> git.proxmox.com Git - rustc.git/blame - vendor/flate2/examples/gzbuilder.rs
New upstream version 1.32.0~beta.2+dfsg1
[rustc.git] / vendor / flate2 / examples / gzbuilder.rs
CommitLineData
ea8adc8c
XL
1extern crate flate2;
2
3use std::io::prelude::*;
4use std::io;
5use std::fs::File;
6use flate2::GzBuilder;
7use flate2::Compression;
8
9// Open file and debug print the contents compressed with gzip
10fn main() {
11 sample_builder().unwrap();
12}
13
14// GzBuilder opens a file and writes a sample string using Builder pattern
15fn 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}