• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 extern crate flate2;
2 
3 use flate2::read::GzEncoder;
4 use flate2::Compression;
5 use std::io;
6 use std::io::prelude::*;
7 
8 // Print the GZ compressed representation of hello world
main()9 fn main() {
10     println!("{:?}", gzencoder_read_hello_world().unwrap());
11 }
12 
13 // Return a vector containing the GZ compressed version of hello world
gzencoder_read_hello_world() -> io::Result<Vec<u8>>14 fn gzencoder_read_hello_world() -> io::Result<Vec<u8>> {
15     let mut result = Vec::new();
16     let c = b"hello world";
17     let mut z = GzEncoder::new(&c[..], Compression::fast());
18     z.read_to_end(&mut result)?;
19     Ok(result)
20 }
21