ddn.compressor.lzma

ddn.compressor.lzma

LZMA/XZ compression/decompression provider built on ddn-lib-lzma.

This module implements the streaming Compressor and Decompressor interfaces from ddn.api.compressor and registers itself under:

  • Enum registry: CompressionFormat.XZ
  • String registry: formatId "xz" with provider name "lib-xz"

The implementation uses liblzma's streaming API (lzma_easy_encoder / lzma_stream_decoder / lzma_code) for true incremental compression and decompression. The produced .xz streams are fully interoperable with the system xz command-line tool.

Provider name convention: vendor "lib", toString() returns "lib-xz".

Module Initializers 1

shared static this()

Types 2

LZMA/XZ compressor that implements ddn.api.compressor.Compressor using liblzma's streaming API (lzma_easy_encoder + lzma_code).

Fields
private CompressionOptions _opts
private OutputSink _sink
private bool _finished
private lzma_stream _strm
private ubyte[] _outBuf
private ulong _bytesIn
private ulong _bytesOut
private lzma_ret _lastCode
Methods
CompressionOptions options() @property constReturn the options used to create this compressor.
void setOutputSink(OutputSink sink)Set the output sink delegate.
void setProgressCallback(ProgressCallback callback)Set the progress callback.
ulong bytesInTotal() @property constTotal uncompressed bytes consumed.
ulong bytesOutTotal() @property constTotal compressed bytes produced.
void write(const(ubyte)[] data)Feed uncompressed data into the stream.
void flush(FlushMode mode = FlushMode.SYNC)Flush pending output.
void finish()Finalize the stream.
void reset()Reset the compression context for reuse.
private void applyEncoder()Apply all stored compression parameters by (re-)initialising the encoder.
private size_t drainEncoder(lzma_action action)Run `lzma_code` with the given action and copy produced bytes to `outBuf`.
bool setDictionary(const(ubyte)[] dict)Set a compression dictionary.
bool isFinished() @property constReturns true if finish() has been called.
Constructors
this(CompressionOptions opts)Create a compressor with provided options.
Destructors

LZMA/XZ decompressor that implements ddn.api.compressor.Decompressor using liblzma's streaming API (lzma_stream_decoder + lzma_code).

Supports concatenated .xz streams: when input contains multiple streams concatenated together, all streams are decompressed in sequence. Trailing bytes that do not form a valid .xz stream are rejected with a CompressionError.

Fields
private DecompressionOptions _opts
private OutputSink _sink
private bool _finished
private lzma_stream _strm
private ubyte[] _outBuf
private ulong _bytesIn
private ulong _bytesOut
private bool _streamEndSeen
Methods
DecompressionOptions options() @property constReturn the options used to create this decompressor.
void setOutputSink(OutputSink sink)Set the output sink delegate.
void setProgressCallback(ProgressCallback callback)Set the progress callback.
ulong bytesInTotal() @property constTotal compressed bytes consumed.
ulong bytesOutTotal() @property constTotal decompressed bytes produced.
void write(const(ubyte)[] data)Feed compressed data into the stream.
void finish()Finalize the stream.
void reset()Reset the decompression context for reuse.
private void applyDecoder()Apply all stored decompression parameters by (re-)initialising the decoder.
bool setDictionary(const(ubyte)[] dict)Provide a dictionary if required.
bool isFinished() @property constReturns true if finish() has been called.
Constructors
this(DecompressionOptions opts)Create a decompressor with provided options.
Destructors

Functions 6

private fnint toLzmaLevel(CompressionOptions opts)Map `CompressionLevel` / `numericLevel` to an LZMA preset (0..9).
private fnlzma_check toLzmaCheck(ChecksumType cs)Map `ChecksumType` to an `lzma_check` value.
private fnErrorCode classifyLzmaError(lzma_ret rc)Map an `lzma_ret` to the most appropriate `ErrorCode`.
private fnvoid throwLzmaError(lzma_ret rc, string context)Throw a `CompressionError` classified from an `lzma_ret` return code.
fnCompressor makeLzmaCompressor(CompressionOptions opts)Factory function that constructs a `LzmaCompressor`.
fnDecompressor makeLzmaDecompressor(DecompressionOptions opts)Factory function that constructs a `LzmaDecompressor`.