ddn.compressor.deflate

ddn.compressor.deflate

Provider for DEFLATE with zlib wrapper format (RFC 1950) for ddn.api.compressor. Uses the pure D zlib implementation from ddn.compressor.zlib. Registers as provider "ddn" for format "deflate_zlib".

This implements the most common DEFLATE format used in PNG, ZIP, HTTP, etc. The zlib wrapper adds a 2-byte header and 4-byte Adler-32 checksum.

  • Supports both streaming and block compression.
  • Fully DDoc-documented.
  • All public functions and types have unittests.

Module Initializers 1

shared static this()

Types 2

DEFLATE compressor using std.zlib/core.c.zlib.

Fields
private CompressionOptions _opts
private OutputSink _sink
private bool _finished
private z_stream _zs
private bool _dictSet
private ulong _bytesIn
private ulong _bytesOut
private int _windowBits
Methods
CompressionOptions options() @property constReturn the options used to create this compressor.
void setOutputSink(OutputSink sink)Set the output sink delegate that will receive produced 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. Throws if finish() was already called or output sink is not set.
void flush(FlushMode mode = FlushMode.SYNC)Flush pending output according to the provided `FlushMode`. - sync -> ZSYNCFLUSH - full -> ZFULLFLUSH
void finish()Finalize the stream and emit trailer. No further writes are allowed afterwards.
void reset()Reset the compression stream to initial state (options retained).
bool setDictionary(const(ubyte)[] dict)Set dictionary if supported. Returns: true if accepted, false if not supported.
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
~thisEnsure zlib stream is ended.

DEFLATE decompressor using std.zlib/core.c.zlib.

Fields
private DecompressionOptions _opts
private OutputSink _sink
private bool _finished
private z_stream _zs
private bool _dictSet
private ulong _bytesIn
private ulong _bytesOut
private int _windowBits
Methods
DecompressionOptions options() @property constReturn the options used to create this decompressor.
void setOutputSink(OutputSink sink)Set the output sink delegate that will receive produced decompressed chunks.
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. Throws if finish() was already called or output sink is not set.
void finish()Signal end-of-input; allows the decompressor to validate checksums and emit any trailing bytes.
void reset()Reset the decompression stream to initial state (options retained).
bool setDictionary(const(ubyte)[] dict)Set dictionary if supported. Returns: true if accepted, false if not supported.
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

Functions 5

private fnint toZLevel(CompressionOptions opts)Map ddn CompressionLevel to zlib level.
private fnint toZStrategy(CompressionOptions opts)Map ddn CompressionStrategy to zlib strategy.
private fnint toZFlush(FlushMode mode)Map ddn FlushMode to zlib flush constant.
fnCompressor makeDeflateStdZlibCompressor(CompressionOptions opts)Factory function that constructs a `DeflateStdZlibCompressor`.
fnDecompressor makeDeflateStdZlibDecompressor(DecompressionOptions opts)Factory function that constructs a `DeflateStdZlibDecompressor`.