Debian Codegraph @

.cargo/vendor/flate2/examples/zlibencoder-read.rs

raw
1 use flate2::read::ZlibEncoder;
2 use flate2::Compression;
3 use std::fs::File;
4 use std::io::prelude::*;
5
6 // Open file and debug print the compressed contents
7 fn main() {
8 println!("{:?}", open_hello_world().unwrap());
9 }
10
11 // Opens sample file, compresses the contents and returns a Vector or error
12 // File implements Read
13 fn open_hello_world() -> std::io::Result<Vec<u8>> {
14 let f = File::open("examples/hello_world.txt")?;
15 let mut z = ZlibEncoder::new(f, Compression::fast());
16 let mut result = Vec::new();
17 z.read_to_end(&mut result)?;
18 Ok(result)
19 }