Sha256: 20d44a9c3a7c3380161ecd19ae6e7d929868926495fb6afbedfc74cf839eb5a7

Contents?: true

Size: 1.06 KB

Versions: 8

Compression:

Stored size: 1.06 KB

Contents

use clap::Parser;
use std::fs;
use std::io;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about=None)]
struct Args {
    /// Files to decompress. With no file, or when given -, read standard input.
    file: Vec<String>,
}

fn main() {
    // This will be a simple application:
    // takes a single (repeatable and optional) argument.
    let args = Args::parse();

    // If nothing was given, act as if `-` was there.
    if args.file.is_empty() {
        decompress_file("-").unwrap();
    } else {
        for file in &args.file {
            decompress_file(file).unwrap();
        }
    }
}

// Dispatch the source reader depending on the filename
fn decompress_file(file: &str) -> io::Result<()> {
    match file {
        "-" => decompress_from(io::stdin()),
        other => decompress_from(io::BufReader::new(fs::File::open(other)?)),
    }
}

// Decompress from a `Reader` into stdout
fn decompress_from<R: io::Read>(r: R) -> io::Result<()> {
    let mut decoder = zstd::Decoder::new(r)?;
    io::copy(&mut decoder, &mut io::stdout())?;
    Ok(())
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/zstd-0.13.2/examples/zstdcat.rs
wasmtime-28.0.0 ./ext/cargo-vendor/zstd-0.13.2/examples/zstdcat.rs
wasmtime-27.0.0 ./ext/cargo-vendor/zstd-0.13.2/examples/zstdcat.rs
wasmtime-26.0.0 ./ext/cargo-vendor/zstd-0.13.2/examples/zstdcat.rs
wasmtime-25.0.2 ./ext/cargo-vendor/zstd-0.13.2/examples/zstdcat.rs
wasmtime-25.0.1 ./ext/cargo-vendor/zstd-0.13.2/examples/zstdcat.rs
wasmtime-25.0.0 ./ext/cargo-vendor/zstd-0.13.2/examples/zstdcat.rs
wasmtime-24.0.0 ./ext/cargo-vendor/zstd-0.13.2/examples/zstdcat.rs