forked from rust-lang/flate2-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rust-lang#329 from MichaelMcDonnell/decompress_file
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
extern crate flate2; | ||
|
||
use flate2::bufread; | ||
use std::env::args; | ||
use std::fs::File; | ||
use std::io::copy; | ||
use std::io::BufReader; | ||
use std::time::Instant; | ||
|
||
fn main() { | ||
// E.g. `cargo run --example decompress_file examples/hello_world.txt.gz hello_world.txt` | ||
if args().len() != 3 { | ||
eprintln!("Usage: ./decompress_file `source` `target`"); | ||
return; | ||
} | ||
let input = BufReader::new(File::open(args().nth(1).unwrap()).unwrap()); | ||
let mut output = File::create(args().nth(2).unwrap()).unwrap(); | ||
let source_len = input.get_ref().metadata().unwrap().len(); | ||
let start = Instant::now(); | ||
let mut decoder = bufread::GzDecoder::new(input); | ||
copy(&mut decoder, &mut output).unwrap(); | ||
println!("Source len: {:?}", source_len); | ||
println!("Target len: {:?}", output.metadata().unwrap().len()); | ||
println!("Elapsed: {:?}", start.elapsed()); | ||
} |
Binary file not shown.