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