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
.xzcontainer.
Structs§
- Adaptive
Ledger - 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.
- Block
Checks - What one worker computed for one output block.
- Checksum
Plan - What to compute, and where the consumer’s boundaries fall.
- Lzma2
Adaptive Decoder - An LZMA2 decoder that is fed input and switches between single- and multi-threaded decoding while it runs.
- Lzma2
Decoder - LZMA2 decoder.
- Lzma2
Encoder - An LZMA2 encoder: blocks of LZMA2 chunks, ending in the end-of-stream control byte.
- Lzma2
MtOptions - How a multi-threaded decode is to be run.
- Lzma2
Parallel Decoder - A prepared multi-threaded LZMA2 decode.
- Lzma2
Parallel Reader - Streaming multi-threaded LZMA2 decoder over any
Read. - Lzma2
Push Encoder - A raw LZMA2 stream, one solid block, encoded from pushed input.
- Lzma2
Reader - Streaming LZMA2 decoder over any
Read. - Lzma2
Run - One independently decodable region of an LZMA2 stream.
- Lzma2
RunChunks - The chunks of one
Lzma2Run, counted and sized by kind. - Lzma2
RunScanner - Incremental discovery of the runs in an LZMA2 stream.
- Lzma2
Writer - Writes a raw LZMA2 stream, the payload an
.xzblock or a 7z coder holds. - Lzma
Alone Header - A parsed
.lzmaheader. - Lzma
Decoder - LZMA1 decoder.
- Lzma
EncProps - C:
CLzmaEncProps. The affinity fields are not carried - nothing in this port pins a thread - butnumThreadsis: it is what turns on the threaded match finder. - Lzma
Encoder - An LZMA1 encoder.
- Lzma
Props - Parsed LZMA properties: the literal-context, literal-position and position bit counts, and the dictionary size.
- Lzma
Push Encoder - A raw LZMA stream encoded from pushed input.
- Lzma
Reader - Streaming LZMA1 decoder over any
Read. - Lzma
Writer - Writes a
.lzma(LZMA-Alone) file. - Normalized
Props - An
LzmaEncPropswith every default resolved. - Progress
- What one decode call did.
- Segment
- One piece of decoded output and its checksum.
- Slice
Stream - A
SeqInStreamover a slice already in memory. - XzEncoder
- The
.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. An.xzstream writer. - XzWriter
- The
.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. Writes an.xzstream.
Enums§
- Checksum
- Which checksum the decoder should compute for each block it produces.
- Drain
Status - Why
Lzma2AdaptiveDecoder::drainstopped. - Error
- Reasons a decode or encode call can fail.
- Finish
Mode - Whether the current output buffer is expected to cover the end of the stream.
- Match
Finder Kind - Which match finder to use.
- Segment
Check - The checksum of one segment, at whichever width was asked for.
- Status
- Where a decode call stopped.
- XzError
Kind - 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 theasmfeature and on every target that has no such loop. - BLOCK_
SIZE_ AUTO - C:
LZMA2_ENC_PROPS_BLOCK_SIZE_AUTO. The sizeauto_block_sizederives from the dictionary. - BLOCK_
SIZE_ SOLID - C:
LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID. One block for the whole input. - DEFAULT_
BLOCK_ SIZE - The
.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. The default block size: what one block may decode to before the writer starts another. - LZMA_
ALONE_ HEADER_ SIZE - Size of a
.lzmaheader 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§
- SeqIn
Stream - A byte source the match finder reads its window from.
- SeqOut
Stream - The output a range encoder flushes into.
Functions§
- auto_
block_ size - The block size
Lzma2EncProps_Normalizederives from a dictionary size. - encode_
lzma2 - Encode
srcas a raw LZMA2 stream, returning it with its property byte. - encode_
lzma2_ mt - Encode
srcas a raw LZMA2 stream with block threads. - encode_
lzma_ alone - Encode
srcas a.lzma(LZMA-Alone) file. - encode_
xz - The
.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. Encodesrcas a whole.xzstream. - encode_
xz_ mt - The
.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. Encodesrcas a whole.xzstream, compressing blocks in parallel. - encode_
xz_ with_ filters - The
.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. The.xzwriter, behind thexzfeature. Encodesrcas a whole.xzstream through a filter chain. - mt_
memory_ estimate - An upper bound on the memory
Lzma2ParallelDecoderwould allocate for these options, without building one. - run_
boundaries - The runs of an LZMA2 stream in a seekable source, without decoding it.