Crate async_sevenz

Crate async_sevenz 

Source
Expand description

This project is an async 7z compressor/decompressor written in pure Rust.

This is a fork of sevenz-rust2, then translated the api to async with async-compression by AI.

§Supported Codecs & filters

CodecDecompressionCompression
COPY
LZMA
LZMA2
BROTLI (*)
BZIP2
DEFLATE (*)
PPMD
LZ4 (*)
ZSTD (*)

(*) Require optional cargo feature.

FilterDecompressionCompression
BCJ X86
BCJ ARM
BCJ ARM64
BCJ ARM_THUMB
BCJ RISC_V
BCJ PPC
BCJ SPARC
BCJ IA64
BCJ2
DELTA

§Usage

use std::path::PathBuf;

use tempfile::tempdir;

use async_sevenz::decompress_file;

#[tokio::main]
async fn main() {
    let mut src = PathBuf::new();
    src.push("examples/data/sample.7z");
    let dest = tempdir().unwrap();
    decompress_file(src, dest.path()).await.expect("complete");
}

§Decompress an encrypted 7z file

use std::path::PathBuf;

use tempfile::tempdir;

use async_sevenz::decompress_file_with_password;

#[tokio::main]
async fn main() {
    let mut src = PathBuf::new();
    src.push("tests/resources/encrypted.7z");
    let dest = tempdir().unwrap();
    decompress_file_with_password(src, dest.path(), "sevenz-rust".into()).await
        .expect("complete");
}

§Compression

use std::path::PathBuf;

use tempfile::tempdir;

use async_sevenz::compress_to_path;

#[tokio::main]
async fn main() {
    let src = PathBuf::from("examples/data/sample");
    let dest_dir = tempdir().unwrap();
    let dest = dest_dir.path().join("sample.7z");
    compress_to_path(src, &dest).await.expect("compress ok");
}

§Compress with AES encryption

use std::path::PathBuf;

use tempfile::tempdir;

use async_sevenz::compress_to_path_encrypted;

#[tokio::main]
async fn main() {
    let src = PathBuf::from("examples/data/sample");
    let dest_dir = tempdir().unwrap();
    let dest = dest_dir.path().join("sample_encrypted.7z");
    compress_to_path_encrypted(src, &dest, "sevenz-rust".into()).await
        .expect("compress ok");
}

§Solid compression

use async_sevenz::ArchiveWriter;

#[tokio::main]
async fn main() {
    let mut writer = ArchiveWriter::create_in_memory()
        .await
        .expect("create writer ok");
    writer
        .push_source_path("examples/data/sample", |_| async { true })
        .await
        .expect("pack ok");
    writer.finish().await.expect("compress ok");
}

§Configure the compression methods

use async_sevenz::{ArchiveWriter, encoder_options};

#[tokio::main]
async fn main() {
    let mut writer = ArchiveWriter::create_in_memory()
        .await
        .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("examples/data/sample", |_| async { true })
        .await
        .expect("pack ok");
    writer.finish().await.expect("compress ok");
}

Modules§

encoder_optionscompress
Encoding options when compressing.

Structs§

Archive
Represents a parsed 7z archive structure.
ArchiveEntry
Represents a single file or directory entry within a 7z archive.
ArchiveReader
Reads a 7z archive file.
ArchiveWritercompress
Writes a 7z archive file.
AutoFinisher
A wrapper around a writer that finishes the stream on drop.
Block
Represents a compression block.
BlockDecoder
Decoder for a specific block within a 7z archive.
Coder
Represents a single coder within a compression block.
EncoderConfigurationcompress
Configuration for encoding methods when compressing data.
EncoderMethod
Encoder method that can be chained (filter, compression and encryption).
NtTime
A type that represents a Windows file time and is used in the 7z archive format.
OrderedCoderIter
Iterator that yields coders in their processing order within a block.
Password
A password used for password protected, encrypted files.
SourceReader
A wrapper around a reader that tracks read count and CRC32.
StreamMap
Mapping structure that correlates files, blocks, and pack streams within an archive.

Enums§

Error
The error type of the crate.

Constants§

K_COMMENT
TODO: Implement reading & writing comments

Traits§

AutoFinish
A trait for writers that finishes the stream on drop.

Functions§

compresscompress and non-WebAssembly
Compresses a source file or directory to a destination writer.
compress_encryptedcompress and non-WebAssembly and aes256
Compresses a source file or directory to a destination writer with password encryption.
compress_to_pathcompress and non-WebAssembly
Compresses a source file or directory to a destination file path.
compress_to_path_encryptedcompress and non-WebAssembly and aes256
Compresses a source file or directory to a destination file path with password encryption.
decompressNon-WebAssembly
Decompresses an archive from a reader to a destination directory.
decompress_fileNon-WebAssembly
Decompresses an archive file to a destination directory.
decompress_file_with_extract_fnNon-WebAssembly
Decompresses an archive file to a destination directory with a custom extraction function.
decompress_file_with_passwordaes256 and non-WebAssembly
Decompresses an encrypted archive file with the given password.
decompress_with_extract_fnNon-WebAssembly
Decompresses an archive from a reader to a destination directory with a custom extraction function.
decompress_with_extract_fn_and_passwordaes256 and non-WebAssembly
Decompresses an encrypted archive from a reader with a custom extraction function and password.
decompress_with_passwordaes256 and non-WebAssembly
Decompresses an encrypted archive from a reader with the given password.
default_entry_extract_fnNon-WebAssembly
Default extraction function that handles standard file and directory extraction.