• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 extern crate flate2;
2 
3 use flate2::bufread::ZlibEncoder;
4 use flate2::Compression;
5 use std::fs::File;
6 use std::io;
7 use std::io::prelude::*;
8 use std::io::BufReader;
9 
10 // Open file and debug print the contents compressed with zlib
main()11 fn main() {
12     println!("{:?}", open_hello_world().unwrap());
13 }
14 
15 // Opens sample file, compresses the contents and returns a Vector or error
16 // File wrapped in a BufReader implements Bufread
open_hello_world() -> io::Result<Vec<u8>>17 fn open_hello_world() -> io::Result<Vec<u8>> {
18     let f = File::open("examples/hello_world.txt")?;
19     let b = BufReader::new(f);
20     let mut z = ZlibEncoder::new(b, Compression::fast());
21     let mut buffer = Vec::new();
22     z.read_to_end(&mut buffer)?;
23     Ok(buffer)
24 }
25