]>
Commit | Line | Data |
---|---|---|
ea8adc8c XL |
1 | extern crate flate2; |
2 | ||
ea8adc8c | 3 | use flate2::read::ZlibEncoder; |
60c5eb7d | 4 | use flate2::Compression; |
ea8adc8c | 5 | use std::fs::File; |
60c5eb7d | 6 | use std::io::prelude::*; |
ea8adc8c XL |
7 | |
8 | // Open file and debug print the compressed contents | |
9 | fn 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 | |
15 | fn open_hello_world() -> std::io::Result<Vec<u8>> { | |
16 | let f = File::open("examples/hello_world.txt")?; | |
ff7c6d11 | 17 | let mut z = ZlibEncoder::new(f, Compression::fast()); |
b7449926 | 18 | let mut buffer = [0; 50]; |
ea8adc8c XL |
19 | let byte_count = z.read(&mut buffer)?; |
20 | Ok(buffer[0..byte_count].to_vec()) | |
21 | } |