Skip to main content

Crate oxiarc_lzma

Crate oxiarc_lzma 

Source
Expand description

§OxiArc LZMA

LZMA (Lempel-Ziv-Markov chain Algorithm) compression and decompression.

LZMA is a lossless data compression algorithm that provides excellent compression ratios. It’s used in:

  • 7-Zip archives (.7z)
  • XZ compressed files (.xz)
  • LZMA-compressed files (.lzma)
  • Some ZIP archives (method 14)

§Features

  • Pure Rust implementation
  • Decompression of LZMA streams
  • Compression with configurable levels
  • Range coder for entropy coding
  • Probability-based context modeling

§Usage

§Decompression

use oxiarc_lzma::decompress;

let compressed = include_bytes!("data.lzma");
let decompressed = decompress(&compressed[..])?;

§Compression

use oxiarc_lzma::{compress, LzmaLevel};

let data = b"Hello, World!";
let compressed = compress(data, LzmaLevel::DEFAULT)?;

§LZMA2 Chunked Encoding (XZ compatible)

use oxiarc_lzma::{encode_lzma2_chunked, decode_lzma2_chunked, LzmaLevel};

let data = b"Hello, LZMA2 chunked world!";
let encoded = encode_lzma2_chunked(data, LzmaLevel::DEFAULT)?;
let decoded = decode_lzma2_chunked(&encoded, 1 << 20)?;

For custom chunk sizes, use Lzma2ChunkedEncoder:

use oxiarc_lzma::{Lzma2ChunkedEncoder, Lzma2Config, LzmaLevel};

let config = Lzma2Config::with_level(LzmaLevel::DEFAULT).chunk_size(64 * 1024);
let mut encoder = Lzma2ChunkedEncoder::with_config(config);
let encoded = encoder.encode(data)?;

§LZMA Format

An LZMA stream consists of:

  1. Properties byte (lc, lp, pb encoded)
  2. Dictionary size (4 bytes, little-endian)
  3. Uncompressed size (8 bytes, little-endian, 0xFFFFFFFFFFFFFFFF = unknown)
  4. Compressed data

The algorithm uses:

  • LZ77-style dictionary compression with sliding window
  • Range coding for entropy encoding
  • Context-dependent probability models

Re-exports§

pub use decoder::LzmaDecoder;
pub use decoder::decompress;
pub use decoder::decompress_raw;
pub use encoder::LzmaEncoder;
pub use encoder::compress;
pub use encoder::compress_raw;
pub use lzma2::Lzma2Decoder;
pub use lzma2::Lzma2Encoder;
pub use lzma2::decode_lzma2;
pub use lzma2::dict_size_from_props;
pub use lzma2::encode_lzma2;
pub use lzma2::props_from_dict_size;
pub use lzma2_chunk::ChunkType;
pub use lzma2_chunk::DEFAULT_CHUNK_SIZE;
pub use lzma2_chunk::LZMA_CHUNK_MAX_COMPRESSED;
pub use lzma2_chunk::LZMA_CHUNK_MAX_UNCOMPRESSED;
pub use lzma2_chunk::Lzma2ChunkedEncoder;
pub use lzma2_chunk::Lzma2Config;
pub use lzma2_chunk::UNCOMPRESSED_CHUNK_MAX;
pub use lzma2_chunk::control;
pub use lzma2_chunk::decode_lzma2_chunked;
pub use lzma2_chunk::encode_lzma2_chunked;
pub use lzma2_chunk::encode_lzma2_with_config;
pub use lzma2_stream::Lzma2StreamDecoder;
pub use lzma2_stream::Lzma2StreamEncoder;
pub use match_finder::Bt4MatchFinder;
pub use match_finder::HashChainMatchFinder;
pub use match_finder::MatchFinder;
pub use memory_pool::LzmaDecoderPooled;
pub use memory_pool::LzmaPool;
pub use memory_pool::PooledBuf;
pub use memory_pool::bucket_for;
pub use model::LzmaModel;
pub use model::LzmaProperties;
pub use model::State;
pub use range_coder::RangeDecoder;
pub use range_coder::RangeEncoder;
pub use streaming::LZMA_COMPRESSOR_DEFAULT_BUDGET;
pub use streaming::LZMA_DECOMPRESSOR_DEFAULT_BUDGET;
pub use streaming::LzmaCompressor;
pub use streaming::LzmaDecompressor;

Modules§

decoder
LZMA decompression.
encoder
LZMA compression.
lzma2
LZMA2 codec for XZ files.
lzma2_chunk
LZMA2 chunking support.
lzma2_stream
Bounded-memory true streaming for LZMA2.
match_finder
Match finder implementations for LZMA compression.
memory_pool
Thread-safe memory pool for LZMA dictionary buffers.
model
LZMA probability models.
optimal
Optimal parsing for LZMA compression.
range_coder
Range coder for LZMA compression.
streaming
Bounded-memory LZMA streaming compressor and decompressor.

Structs§

LzmaLevel
LZMA compression level.

Enums§

Error
Re-export of the core error type for convenient use in tests and downstream crates. The main error type for OxiArc operations.

Functions§

compress_bytes
Compress data to a Vec using default settings.
decompress_bytes
Decompress LZMA data to a Vec.
lzma2_compress
Compress data to an LZMA2 stream using the given numeric compression level.
lzma2_decompress
Decompress an LZMA2 stream produced by lzma2_compress or LzmaCompressor::compress.