28 releases (13 breaking)
Uses new Rust 2024
| 0.20.1 | Jan 1, 2026 |
|---|---|
| 0.20.0 | Dec 7, 2025 |
| 0.19.4 | Nov 27, 2025 |
| 0.17.1 | Jul 26, 2025 |
| 0.13.0 | Mar 31, 2025 |
#41 in Compression
28,279 downloads per month
Used in 30 crates
(15 directly)
1MB
5.5K
SLoC
Contains (DOS exe, 370KB) tests/resources/decompress_x86.exe, (DOS exe, 360KB) tests/resources/decompress_arm64.exe
This project is a 7z compressor/decompressor written in pure Rust.
This is a fork of the original, unmaintained sevenz-rust crate to continue the development and maintenance.
Supported Codecs & filters
| Codec | Decompression | Compression |
|---|---|---|
| COPY | ✓ | ✓ |
| LZMA | ✓ | ✓ |
| LZMA2 | ✓ | ✓ |
| BROTLI (*) | ✓ | ✓ |
| BZIP2 | ✓ | ✓ |
| DEFLATE (*) | ✓ | ✓ |
| PPMD | ✓ | ✓ |
| LZ4 (*) | ✓ | ✓ |
| ZSTD (*) | ✓ | ✓ |
(*) Require optional cargo feature.
| Filter | Decompression | Compression |
|---|---|---|
| BCJ X86 | ✓ | ✓ |
| BCJ ARM | ✓ | ✓ |
| BCJ ARM64 | ✓ | ✓ |
| BCJ ARM_THUMB | ✓ | ✓ |
| BCJ RISC_V | ✓ | ✓ |
| BCJ PPC | ✓ | ✓ |
| BCJ SPARC | ✓ | ✓ |
| BCJ IA64 | ✓ | ✓ |
| BCJ2 | ✓ | |
| DELTA | ✓ | ✓ |
Usage
[dependencies]
sevenz-rust2 = { version = "0.20" }
Decompress source file "data/sample.7z" to destination path "data/sample":
sevenz_rust2::decompress_file("data/sample.7z", "data/sample").expect("complete");
Decompress an encrypted 7z file
Use the helper function to encrypt and decompress source file "path/to/encrypted.7z" to destination path "data/sample":
sevenz_rust2::decompress_file_with_password("path/to/encrypted.7z", "data/sample", "password".into()).expect("complete");
Compression
Use the helper function to create a 7z file with source path:
sevenz_rust2::compress_to_path("examples/data/sample", "examples/data/sample.7z").expect("compress ok");
Compress with AES encryption
Use the helper function to create a 7z file with source path and password:
sevenz_rust2::compress_to_path_encrypted("examples/data/sample", "examples/data/sample.7z", "password".into()).expect("compress ok");
Advanced Usage
Solid compression
Solid archives can in theory provide better compression rates, but decompressing a file needs all previous data to also be decompressed.
use sevenz_rust2::*;
let mut writer = ArchiveWriter::create("dest.7z").expect("create writer ok");
writer.push_source_path("path/to/compress", | _ | true).expect("pack ok");
writer.finish().expect("compress ok");
Configure the compression methods
With encryption and lzma2 options:
use sevenz_rust2::*;
let mut writer = ArchiveWriter::create("dest.7z").expect("create writer ok");
writer.set_content_methods(vec![
encoder_options::AesEncoderOptions::new("sevenz-rust".into()).into(),
encoder_options::Lzma2Options::from_level(9).into(),
]);
writer.push_source_path("path/to/compress", | _ | true).expect("pack ok");
writer.finish().expect("compress ok");
WASM support
WASM is supported, but you can't use the default features. We provide a "default_wasm" feature that contains all default features with the needed changes to support WASM:
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' cargo build --target wasm32-unknown-unknown --no-default-features --features=default_wasm
Licence
Licensed under the Apache License, Version 2.0.
Dependencies
~1.6–4.5MB
~111K SLoC