Crates.io | sevenz-rust2 |
lib.rs | sevenz-rust2 |
version | 0.18.0 |
created_at | 2025-02-24 08:03:03.422173+00 |
updated_at | 2025-08-25 06:33:03.048707+00 |
description | A 7z decompressor/compressor written in pure Rust |
homepage | https://github.com/hasenbanck/sevenz-rust2 |
repository | https://github.com/hasenbanck/sevenz-rust |
max_upload_size | |
id | 1567181 |
size | 1,763,165 |
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.
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 | ✓ | ✓ |
[dependencies]
sevenz-rust2 = { version = "0.18" }
Decompress source file "data/sample.7z" to destination path "data/sample":
sevenz_rust2::decompress_file("data/sample.7z", "data/sample").expect("complete");
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");
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");
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");
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");
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 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
Licensed under the Apache License, Version 2.0.