| 1 |
use flate2::bufread; |
| 2 |
use std::env::args; |
| 3 |
use std::fs::File; |
| 4 |
use std::io::copy; |
| 5 |
use std::io::BufReader; |
| 6 |
use std::time::Instant; |
| 7 |
|
| 8 |
fn main() { |
| 9 |
// E.g. `cargo run --example decompress_file examples/hello_world.txt.gz hello_world.txt` |
| 10 |
if args().len() != 3 { |
| 11 |
eprintln!("Usage: ./decompress_file `source` `target`"); |
| 12 |
return; |
| 13 |
} |
| 14 |
let input = BufReader::new(File::open(args().nth(1).unwrap()).unwrap()); |
| 15 |
let mut output = File::create(args().nth(2).unwrap()).unwrap(); |
| 16 |
let source_len = input.get_ref().metadata().unwrap().len(); |
| 17 |
let start = Instant::now(); |
| 18 |
let mut decoder = bufread::GzDecoder::new(input); |
| 19 |
copy(&mut decoder, &mut output).unwrap(); |
| 20 |
println!("Source len: {source_len:?}"); |
| 21 |
println!("Target len: {:?}", output.metadata().unwrap().len()); |
| 22 |
println!("Elapsed: {:?}", start.elapsed()); |
| 23 |
} |