| Crates.io | decompress |
| lib.rs | decompress |
| version | 0.6.0 |
| created_at | 2022-11-28 13:27:22.434595+00 |
| updated_at | 2023-02-27 15:09:43.656904+00 |
| description | Extracting archives made easy |
| homepage | |
| repository | https://github.com/rusty-ferris-club/decompress |
| max_upload_size | |
| id | 724439 |
| size | 237,389 |
A library that supports decompression of archives in multiple formats, inspired by ergonomics from Node's decompress.
zip, tar, tar.gz, tar.bz2, tar.xz, tar.zst (zstd compression), ar (Unix Archive)cargo features to avoid compiling formats you don't need[dependencies]
decompress = "0.1.0"
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 (c) 2022 @jondot. See LICENSE for further details.