Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rusty-ferris-club/decompress
Extracting archives made easy for Rust 🦀
https://github.com/rusty-ferris-club/decompress
decompress rust rust-lang tar unpack zip
Last synced: 2 days ago
JSON representation
Extracting archives made easy for Rust 🦀
- Host: GitHub
- URL: https://github.com/rusty-ferris-club/decompress
- Owner: rusty-ferris-club
- License: apache-2.0
- Created: 2022-11-28T13:22:31.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-07-15T15:45:06.000Z (over 1 year ago)
- Last Synced: 2024-10-13T13:28:17.045Z (about 1 month ago)
- Topics: decompress, rust, rust-lang, tar, unpack, zip
- Language: Rust
- Homepage:
- Size: 143 KB
- Stars: 7
- Watchers: 3
- Forks: 4
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Decompress
[](https://github.com/rusty-ferris-club/decompress)
[](https://crates.io/crates/decompress)
[](https://docs.rs/decompress)
[](https://github.com/rusty-ferris-club/decompress/actions?query=branch%3Amaster)A library that supports decompression of archives in multiple formats, inspired by ergonomics from Node's [decompress](https://github.com/kevva/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
```toml
[dependencies]
decompress = "0.1.0"
```# Usage
Default use:
```rust
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):
```rust
decompress::decompress(archive, to, &ExtractOpts{ strip: 1 });
```A micro optimization:
```rust
let decompressor = decompress::Decompress::default()
// use decompressor
// decompressor.decompress(...)
```Build your own stack:
```rust
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](https://github.com/kevva/decompress)
```rust
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
```rust
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](http://twitter.com/jondot). See [LICENSE](LICENSE.txt) for further details.