ddn.compressor.lzo

ddn.compressor.lzo

LZO compression provider for ddn.api.compressor.

This module provides a basic LZO compression and decompression implementation using a simplified LZO1X-style format. It includes:

  • Streaming Compressor and Decompressor classes implementing the ddn.api.compressor interface.
  • Hash-based match finding with configurable compression levels (0-9).
  • Simple block format with headers and checksums.
  • Efficient compression suitable for in-memory data.

LZO (Lempel-Ziv-Oberhumer) is a lossless data compression algorithm that is focused on decompression speed. It is widely used in applications where fast decompression is critical.

Important: This implementation uses a simplified format that is NOT compatible with the lzop command-line tool or standard LZO file format. It is designed for use within the ddn.compressor API for internal data compression where interoperability with external tools is not required.

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.
  • Levels 4-6: Default compression with medium hash tables.
  • Levels 7-9: Better compression with larger hash tables.

The default compression level is 3, providing a good balance between compression ratio and speed.

Module Initializers 1

shared static this()

Types 2

LZO compressor that implements ddn.api.compressor.Compressor.

This class provides streaming compression using the LZO1X algorithm. Internally it uses a pre-allocated malloc'd hash table and a buffer-offset tracking scheme to avoid unnecessary copies on block boundaries.

Methods
CompressionOptions options() @property constReturn the options used to create this compressor.
void setOutputSink(OutputSink sink)Set the output sink delegate that will receive compressed chunks.
void setProgressCallback(ProgressCallback callback)Set an optional progress callback.
ulong bytesInTotal() @property constTotal uncompressed bytes consumed since last reset.
ulong bytesOutTotal() @property constTotal compressed bytes produced since last reset.
void write(const(ubyte)[] data)Feed more uncompressed data.
void flush(FlushMode mode = FlushMode.SYNC)Flush pending output.
void finish()Finalize the stream. No further writes are allowed.
void reset()Reset the compression stream to initial state.
bool setDictionary(const(ubyte)[] dict)Set dictionary (not supported for LZO).
bool isFinished() @property constReturns true if finish() has been called and the stream is closed for further writes.
Constructors
this(CompressionOptions opts)Create a compressor with provided options.
Destructors
~thisDestructor – frees the `malloc`'d hash table, output buffer, and block buffer.

LZO decompressor that implements ddn.api.compressor.Decompressor.

Methods
DecompressionOptions options() @property constReturn the options used to create this decompressor.
void setOutputSink(OutputSink sink)Set the output sink delegate for decompressed data.
void setProgressCallback(ProgressCallback callback)Set an optional progress callback.
ulong bytesInTotal() @property constTotal compressed bytes consumed since last reset.
ulong bytesOutTotal() @property constTotal decompressed bytes produced since last reset.
void write(const(ubyte)[] data)Feed more compressed data.
void finish()Finish the stream.
void reset()Reset the decompression stream.
bool setDictionary(const(ubyte)[] dict)Set dictionary (not supported for LZO).
bool isFinished() @property constReturns true if finish() has been called and the stream is closed for further writes.
Constructors
this(DecompressionOptions opts)Create a decompressor with provided options.
Destructors
~thisDestructor – frees the `malloc`'d decompression buffer.

Functions 2

fnCompressor makeLzoCompressor(CompressionOptions opts)Factory function that constructs an `LzoCompressor`.
fnDecompressor makeLzoDecompressor(DecompressionOptions opts)Factory function that constructs an `LzoDecompressor`.