compress-tools
The compress-tools crate aims to provide a convenient and easy to use set
of methods which builds on top of libarchive exposing a small set of its
functionalities.
| Platform | Build Status |
|---|---|
| Linux - x86_64 | |
| macOS - aarch64 | |
| Windows - x86_64 |
Dependencies
You must have libarchive, 3.2.0 or newer, properly installed on your
system in order to use this. If building on *nix and Windows GNU
systems, pkg-config is used to locate the libarchive; on Windows
MSVC, vcpkg will be used to locating the libarchive.
Typical install:
- Debian/Ubuntu:
apt install libarchive-dev pkg-config - macOS (Homebrew):
brew install libarchive pkg-config(libarchive is keg-only; expose it viaPKG_CONFIG_PATH="$(brew --prefix libarchive)/lib/pkgconfig") - Windows MSVC:
vcpkg install libarchive
The minimum supported Rust version is 1.82.
Install
[]
= "0.16"
To enable async support backed by tokio:
[]
= { = "0.16", = ["tokio_support"] }
See Feature flags for the full list.
Upgrading to 0.16
0.16.0 introduces a few breaking changes. See CHANGES.md for the complete list; the highlights are:
- Archive entry points now reject non-archive input.
list_archive_files,list_archive_entries,uncompress_archive,uncompress_archive_file, andArchiveIterator(and their_with_encoding/ async variants) no longer treat arbitrary byte streams as a single-entry archive nameddata. If you relied on that behavior with the iterator, opt back in withArchiveIteratorBuilder::raw_format(true). Raw compressed streams remain handled byuncompress_data. - Async entry points require
AsyncSeek. The async variants oflist_archive_files,uncompress_archive, anduncompress_archive_filenow bound the source onAsyncRead + AsyncSeek. Wraptokio::fs::Fileviatokio_util::compatas needed. Error::Extractionchanged shape. It now carries adetailsstring and an optionalio::Errorreconstructed fromarchive_errno. Match arms usingError::Extraction(msg)should be rewritten asError::Extraction { details, .. }.- New
Error::UnsupportedZipCompressionvariant. ZIP archives using Deflate64 (method 9) are now rejected up front instead of failing mid-extraction. Exhaustivematcharms onErrorneed a new branch (or a catch-all). - MSRV raised to 1.82.0 (was 1.65.0). Older toolchains will fail to build.
Features
This crate is capable of extracting:
- compressed files
- archive files
- a single file from an archive
Extract an entire archive
use *;
use File;
use Path;
let mut source = open?;
let dest = new;
uncompress_archive?;
Extract a single file from an archive
use uncompress_archive_file;
use File;
let mut source = open?;
let mut target = create?;
uncompress_archive_file?;
Iterate over archive entries
use ;
use File;
let source = open?;
let iter = new.build?;
for content in iter
List entries with sizes
use list_archive_entries;
use File;
let mut source = open?;
for entry in list_archive_entries?
Asynchronous iteration (tokio)
Requires the tokio_support feature.
use ArchiveIteratorBuilder;
use ArchiveContents;
use StreamExt;
use File;
async
Password-protected ZIP archives
use ;
use File;
let source = open?;
let iter = new
.with_password
.build?;
for _content in iter
Feature flags
| Flag | Purpose |
|---|---|
async_support |
Base, executor-agnostic async primitives. |
futures_support |
async_support plus blocking integration for the futures ecosystem. |
tokio_support |
async_support plus tokio / tokio-util integration. |
static |
Statically link all bundled archive libraries and enable the default Windows imports. |
static_b2, static_lz4, static_zstd, static_lzma, static_bz2, static_z, static_xml2 |
Selective static linking, one per bundled dependency. |
win_user32, win_crypt32, win_advapi32, win_xmllite |
Windows system import libraries (all enabled by default). |
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.