Skip to main content

Crate lzma_turbo

Crate lzma_turbo 

Source
Expand description

LZMA and LZMA2 decoding, ported from the 7-Zip reference decoder.

The decoder in this crate is a port of Igor Pavlov’s LzmaDec.c and Lzma2Dec.c from the LZMA SDK (public domain), kept structurally faithful to the original so that its speed carries over: one large decode loop with the range coder, probability base and dictionary pointers held in locals, limits checked once per symbol under a caller-guaranteed margin, and a separate careful path for the bytes near buffer edges.

The encoder is a port of the same SDK’s LzFind.c, LzmaEnc.c and Lzma2Enc.c, and is bit-exact with it. See docs/encoder.md.

§Example

The reader adapters need std; without it the example below cannot run, so it is compiled only when the std feature is on.

use std::fs::File;
use std::io::Read;
use lzma_turbo::LzmaReader;

let mut out = Vec::new();
LzmaReader::new(File::open("archive.lzma")?)?.read_to_end(&mut out)?;

§Provenance

Derived from C/LzmaDec.c and C/Lzma2Dec.c of the LZMA SDK, which are in the public domain. Each ported function names its C counterpart in a comment.

Re-exports§

pub use xz::XzAdaptiveDecoder;
pub use xz::XzError;
pub use xz::XzOptions;
pub use xz::XzParallelReader;
pub use xz::XzReader;

Modules§

checksum
Checksums computed where the bytes are, not where they are written.
crc
The checksums the container formats around LZMA use.
crypto
SHA-256, as the xz container uses it.
filters
The in-place converters that sit in front of an LZMA2 stream: the branch/call/jump family (bcj) and the delta filter (delta).
run
Bounded dictionary decoding of one independently reset LZMA2 run.
xz
The .xz container.

Structs§

AdaptiveLedger
Where the decoder’s memory is, and why it last held work back: what a caller tuning its read-ahead, or a harness explaining a decode, reads to see the mechanism rather than guess at it.
BlockChecks
What one worker computed for one output block.
ChecksumPlan
What to compute, and where the consumer’s boundaries fall.
Lzma2AdaptiveDecoder
An LZMA2 decoder that is fed input and switches between single- and multi-threaded decoding while it runs.
Lzma2Decoder
LZMA2 decoder.
Lzma2Encoder
An LZMA2 encoder: blocks of LZMA2 chunks, ending in the end-of-stream control byte.
Lzma2MtOptions
How a multi-threaded decode is to be run.
Lzma2ParallelDecoder
A prepared multi-threaded LZMA2 decode.
Lzma2ParallelReader
Streaming multi-threaded LZMA2 decoder over any Read.
Lzma2PushEncoder
A raw LZMA2 stream, one solid block, encoded from pushed input.
Lzma2Reader
Streaming LZMA2 decoder over any Read.
Lzma2Run
One independently decodable region of an LZMA2 stream.
Lzma2RunChunks
The chunks of one Lzma2Run, counted and sized by kind.
Lzma2RunScanner
Incremental discovery of the runs in an LZMA2 stream.
Lzma2Writer
Writes a raw LZMA2 stream, the payload an .xz block or a 7z coder holds.
LzmaAloneHeader
A parsed .lzma header.
LzmaDecoder
LZMA1 decoder.
LzmaEncProps
C: CLzmaEncProps. The affinity fields are not carried - nothing in this port pins a thread - but numThreads is: it is what turns on the threaded match finder.
LzmaEncoder
An LZMA1 encoder.
LzmaProps
Parsed LZMA properties: the literal-context, literal-position and position bit counts, and the dictionary size.
LzmaPushEncoder
A raw LZMA stream encoded from pushed input.
LzmaReader
Streaming LZMA1 decoder over any Read.
LzmaWriter
Writes a .lzma (LZMA-Alone) file.
NormalizedProps
An LzmaEncProps with every default resolved.
Progress
What one decode call did.
Segment
One piece of decoded output and its checksum.
SliceStream
A SeqInStream over a slice already in memory.
XzEncoder
The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. An .xz stream writer.
XzWriter
The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. Writes an .xz stream.

Enums§

Checksum
Which checksum the decoder should compute for each block it produces.
DrainStatus
Why Lzma2AdaptiveDecoder::drain stopped.
Error
Reasons a decode or encode call can fail.
FinishMode
Whether the current output buffer is expected to cover the end of the stream.
MatchFinderKind
Which match finder to use.
SegmentCheck
The checksum of one segment, at whichever width was asked for.
Status
Where a decode call stopped.
XzErrorKind
Why an xz read failed.

Constants§

ASM_LOOP
Whether this build decodes with the assembly loop ported from the LZMA SDK’s Asm/ tree rather than with the portable Rust port of the C loop. False without the asm feature and on every target that has no such loop.
BLOCK_SIZE_AUTO
C: LZMA2_ENC_PROPS_BLOCK_SIZE_AUTO. The size auto_block_size derives from the dictionary.
BLOCK_SIZE_SOLID
C: LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID. One block for the whole input.
DEFAULT_BLOCK_SIZE
The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. The default block size: what one block may decode to before the writer starts another.
LZMA_ALONE_HEADER_SIZE
Size of a .lzma header in bytes.
LZMA_MATCH_LEN_MAX
C: LZMA_MATCH_LEN_MAX.
LZMA_MATCH_LEN_MIN
C: LZMA_MATCH_LEN_MIN.
LZMA_PROPS_SIZE
C: LZMA_PROPS_SIZE (C/LzmaDec.h).
LZMA_REQUIRED_INPUT_MAX
C: LZMA_REQUIRED_INPUT_MAX (C/LzmaDec.h). Number of input bytes needed for the worst-case single LZMA symbol; the margin the fast loop relies on.
VERSION
Crate version, for consumers that record which decoder produced an output.

Traits§

SeqInStream
A byte source the match finder reads its window from.
SeqOutStream
The output a range encoder flushes into.

Functions§

auto_block_size
The block size Lzma2EncProps_Normalize derives from a dictionary size.
encode_lzma2
Encode src as a raw LZMA2 stream, returning it with its property byte.
encode_lzma2_mt
Encode src as a raw LZMA2 stream with block threads.
encode_lzma_alone
Encode src as a .lzma (LZMA-Alone) file.
encode_xz
The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. Encode src as a whole .xz stream.
encode_xz_mt
The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. Encode src as a whole .xz stream, compressing blocks in parallel.
encode_xz_with_filters
The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. The .xz writer, behind the xz feature. Encode src as a whole .xz stream through a filter chain.
mt_memory_estimate
An upper bound on the memory Lzma2ParallelDecoder would allocate for these options, without building one.
run_boundaries
The runs of an LZMA2 stream in a seekable source, without decoding it.