| 1 |
use clap::Parser; |
| 2 |
use std::fs; |
| 3 |
use std::io; |
| 4 |
|
| 5 |
#[derive(Parser, Debug)] |
| 6 |
#[command(author, version, about, long_about=None)] |
| 7 |
struct Args { |
| 8 |
|
| 9 |
file: Vec<String>, |
| 10 |
} |
| 11 |
|
| 12 |
fn main() { |
| 13 |
|
| 14 |
|
| 15 |
let args = Args::parse(); |
| 16 |
|
| 17 |
|
| 18 |
if args.file.is_empty() { |
| 19 |
decompress_file("-").unwrap(); |
| 20 |
} else { |
| 21 |
for file in &args.file { |
| 22 |
decompress_file(file).unwrap(); |
| 23 |
} |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
fn decompress_file(file: &str) -> io::Result<()> { |
| 29 |
match file { |
| 30 |
"-" => decompress_from(io::stdin()), |
| 31 |
other => decompress_from(io::BufReader::new(fs::File::open(other)?)), |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
fn decompress_from<R: io::Read>(r: R) -> io::Result<()> { |
| 37 |
let mut decoder = zstd::Decoder::new(r)?; |
| 38 |
io::copy(&mut decoder, &mut io::stdout())?; |
| 39 |
Ok(()) |
| 40 |
} |