ddn.compressor.lz4
ddn.compressor.lz4
LZ4 compression provider for ddn.api.compressor.
This module provides a complete LZ4 compression and decompression implementation conforming to the LZ4 frame format specification. It includes:
- Streaming
CompressorandDecompressorclasses implementing theddn.api.compressorinterface. - Hash-based match finding with configurable compression levels (0-9).
- Support for both greedy and lazy (HC) matching strategies.
- Full LZ4 frame format support including magic numbers, frame descriptors, block headers, and checksums.
- Interoperability with the standard
lz4command-line tool.
Compression levels control the trade-off between speed and compression ratio:
- Level 0: Store-only mode (no compression, fastest).
- Levels 1-3: Fast compression with smaller hash tables (4KB-16KB).
- Levels 4-6: Default compression with 64KB hash table.
- Levels 7-9: High compression (HC mode) with lazy matching for better compression ratios at the cost of speed.
The default compression level is 3, matching the behaviour of the standard lz4 tool.
Module Initializers 1
()Types 2
Streaming LZ4 compressor implementing the Compressor interface.
The compressor currently emits a single LZ4 frame per stream using independent blocks, no block checksums, and a content checksum. The frame layout is compatible with the lz4 CLI tool.
void setOutputSink(OutputSink sink)Set the output sink that will receive compressed bytes.void setProgressCallback(ProgressCallback callback)Set an optional progress callback.void write(const(ubyte)[] data)Feed more uncompressed data into the compressor.void flush(FlushMode mode = FlushMode.SYNC)Flush buffered input as one or more complete frame blocks.void finish()Finalise the compression stream.void reset()Reset the compressor to its initial state.bool setDictionary(const(ubyte)[] dict)Set or update the compression dictionary.bool isFinished() @property constReturns true if finish() has been called and the stream is closed for further writes.this(CompressionOptions opts)Construct a new LZ4 compressor with the given options.Streaming LZ4 decompressor implementing the Decompressor interface.
The implementation accepts standard LZ4 frame streams and decodes them incrementally block-by-block as input arrives.
DecompressionOptions options() @property constReturn the options this decompressor was created with.void setOutputSink(OutputSink sink)Set the output sink that will receive decompressed bytes.void setProgressCallback(ProgressCallback callback)Set an optional progress callback.void write(const(ubyte)[] data)Feed more compressed data into the decompressor.void finish()Signal end-of-input to the decompressor.void reset()Reset the decompressor to its initial state.bool setDictionary(const(ubyte)[] dict)Set or update the decompression dictionary.bool isFinished() @property constReturns true if finish() has been called and the stream is closed for further writes.this(DecompressionOptions opts)Construct a new LZ4 decompressor with the given options.ParseStateIncremental frame parser state.