GithubHelp home page GithubHelp logo

rusty-ferris-club / decompress Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 3.0 146 KB

Extracting archives made easy for Rust ๐Ÿฆ€

License: Apache License 2.0

Rust 98.74% Shell 1.26%
decompress rust rust-lang tar unpack zip

decompress's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.