6 releases (breaking)

0.6.0 Feb 27, 2023
0.5.0 Feb 27, 2023
0.4.0 Feb 27, 2023
0.3.0 Jan 21, 2023
0.1.0 Nov 28, 2022

#124 in Compression

Download history 13/week @ 2023-02-10 40/week @ 2023-02-17 70/week @ 2023-02-24 18/week @ 2023-03-03 64/week @ 2023-03-10 17/week @ 2023-03-17 28/week @ 2023-03-24 6/week @ 2023-03-31 31/week @ 2023-04-07 9/week @ 2023-04-14 783/week @ 2023-04-21 904/week @ 2023-04-28 901/week @ 2023-05-05 1176/week @ 2023-05-12 666/week @ 2023-05-19 1253/week @ 2023-05-26

4,150 downloads per month
Used in 2 crates

Apache-2.0

47KB
1K SLoC

Decompress

github crates.io docs.rs build status

A library that supports decompression of archives in multiple formats, inspired by ergonomics from Node's decompress.

  • Includes a default stack of decompressors supporting: zip, tar, tar.gz, tar.bz2, tar.xz, tar.zst (zstd compression), ar (Unix Archive)
  • Build your own decompressors and add them
  • Compose a custom stack (exclude compressors, respond to different file extensions)
  • Use cargo features to avoid compiling formats you don't need

Dependency

[dependencies]
decompress = "0.1.0"

Usage

Default use:

decompress::decompress(archive, to, &ExtractOpts::default());

Strip the first component of all paths in the archive (for when you have a wrapper folder you don't need):

decompress::decompress(archive, to, &ExtractOpts{ strip: 1 });

A micro optimization:

let decompressor = decompress::Decompress::default()
// use decompressor
// decompressor.decompress(...)

Build your own stack:

use regex::Regex;
let decompressor = decompress::Decompress::build(vec![decompressors::zip::Zip::build(Some(
    Regex::new(r".*").unwrap(),
))]);
// use decompressor
// decompressor.decompress(...)

It's also possible to filter unwanted files, similar to nodejs decompress

let decompressor = decompress::Decompress::default();
let res = decompressor.decompress(
    archive,
    to,
    &ExtractOptsBuilder::default()
        .strip(strip)
        .filter(|path| {
            if let Some(path) = path.to_str() {
            return path.ends_with("abc.sh");
            }
            false
        })
        .build()
        .unwrap(),
);

Mapping paths is also supported

let decompressor = decompress::Decompress::default();
let res = decompressor.decompress(
    archive,
    to,
    &ExtractOptsBuilder::default()
        .strip(strip)
        .map(|path| {
            let mut path = path.to_path_buf();
            path.set_file_name(format!(
                "abc-{}",
                path.file_name().unwrap().to_str().unwrap()
            ));
            path.into()
        })
        .build()
        .unwrap(),
);

Copyright

Copyright (c) 2022 @jondot. See LICENSE for further details.

Dependencies

~2–8.5MB
~155K SLoC