#decompression #7z #7zip #sevenz

sevenz-rust

A 7z decompressor/compressor written in pure rust

25 releases

0.6.0 Apr 5, 2024
0.5.4 Dec 14, 2023
0.5.3 Sep 29, 2023
0.4.3 Jun 16, 2023
0.1.5 Nov 2, 2022

#22 in Compression

Download history 4762/week @ 2024-02-01 4350/week @ 2024-02-08 4258/week @ 2024-02-15 3951/week @ 2024-02-22 3532/week @ 2024-02-29 3840/week @ 2024-03-07 3988/week @ 2024-03-14 4706/week @ 2024-03-21 3674/week @ 2024-03-28 3003/week @ 2024-04-04 3030/week @ 2024-04-11 2588/week @ 2024-04-18 2773/week @ 2024-04-25 2722/week @ 2024-05-02 2705/week @ 2024-05-09 2560/week @ 2024-05-16

11,141 downloads per month
Used in 17 crates (14 directly)

Apache-2.0

695KB
9K SLoC

Contains (DOS exe, 370KB) tests/resources/decompress_x86.exe

Crate Documentation

This project is a 7z compressor/decompressor written in pure rust.
And it's very much inspired by the apache commons-compress project.

The LZMA/LZMA2 decoder and all filters code was ported from tukaani xz for java

Decompression

Supported codecs:

  • BZIP2 (require feature 'bzip2')
  • COPY
  • LZMA
  • LZMA2
  • ZSTD (require feature 'zstd')

Supported filters:

  • BCJ X86
  • BCJ PPC
  • BCJ IA64
  • BCJ ARM
  • BCJ ARM_THUMB
  • BCJ SPARC
  • DELTA
  • BJC2

Usage

[dependencies]
sevenz-rust={version="0.2"}

Decompress source file "data/sample.7z" to dest path "data/sample"

sevenz_rust::decompress_file("data/sample.7z", "data/sample").expect("complete");

Decompress a encrypted 7z file

Add 'aes256' feature

[dependencies]
sevenz-rust={version="0.2", features=["aes256"]}
sevenz_rust::decompress_file_with_password("path/to/encrypted.7z", "path/to/output", "password".into()).expect("complete");

Multi-thread decompress

check examples/mt_decompress

Compression

Currently only support LZMA2 method.

[dependencies]
sevenz-rust={version="0.5.0", features=["compress"]}

Use the helper function to create a 7z file with source path.

sevenz_rust::compress_to_path("examples/data/sample", "examples/data/sample.7z").expect("compress ok");

With AES encryption

require version>=0.3.0

[dependencies]
sevenz-rust={version="0.5", features=["compress","aes256"]}

Use the helper function to create a 7z file with source path and password.

sevenz_rust::compress_to_path_encrypted("examples/data/sample", "examples/data/sample.7z", "password".into()).expect("compress ok");

Advance

[dependencies]
sevenz-rust={version="0.5.0", features=["compress","aes256"]}

Solid compression

use sevenz_rust::*;

let mut sz = SevenZWriter::create("dest.7z").expect("create writer ok");

sz.push_source_path("path/to/compress", |_| true).expect("pack ok");

sz.finish().expect("compress ok");

Compression methods

with encryption and lzma2 options

use sevenz_rust::*;

let mut sz = SevenZWriter::create("dest.7z").expect("create writer ok");
sz.set_content_methods(vec![
    sevenz_rust::AesEncoderOptions::new("sevenz-rust".into()).into(),
    lzma::LZMA2Options::with_preset(9).into(),
]);
sz.push_source_path("path/to/compress", |_| true).expect("pack ok");

sz.finish().expect("compress ok");

Changelog

Dependencies

~1.6–9.5MB
~92K SLoC