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 ret_vec = [0; 100];
16     let c = b"hello world";
17     let mut z = GzEncoder::new(&c[..], Compression::fast());
18     let count = z.read(&mut ret_vec)?;
19     Ok(ret_vec[0..count].to_vec())
20 }
21