ddn.compressor.gzip

ddn.compressor.gzip

Rock-solid GZIP compression/decompression provider built on ddn.compressor.zlib (pure D implementation)

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

  • Enum registry: CompressionFormat.gzip
  • String registry: formatId "gzip" with provider name "ddn"

The implementation uses zlib's deflate/inflate with appropriate window bits to produce/consume GZIP containers. No external packages are required.

Provider name convention: "ddn" (short name, toString() returns "ddn-gzip").

Module Initializers 1

shared static this()

Types 2

GZIP compressor that implements ddn.api.compressor.Compressor using zlib's deflate with GZIP container (via deflateInit2 and windowBits = 16 + window size).

Fields
private CompressionOptions _opts
private OutputSink _sink
private bool _finished
private z_stream _zs
private ubyte[] _outBuf
private bool _inited
private bool _dictSet
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. For gzip container this usually returns false.
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.

GZIP decompressor that implements ddn.api.compressor.Decompressor using zlib's inflate with auto header detection (windowBits = 15 + 32).

Fields
private DecompressionOptions _opts
private OutputSink _sink
private bool _finished
private z_stream _zs
private ubyte[] _outBuf
private bool _inited
private bool _needDict
private bool _sawStreamEnd
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 into the stream.
void finish()Finish the stream; validates that end-of-stream was reached, otherwise throws `truncated`.
void reset()Reset the decompression stream to initial state.
bool setDictionary(const(ubyte)[] dict)Provide a dictionary if requested by the compressed stream.
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
~thisEnsure zlib stream is ended.

Functions 6

private fnint toZLevel(CompressionOptions opts)Map high-level `CompressionLevel`/numericLevel to zlib level (0..9 or ZDEFAULTCOMPRESSION).
private fnint toZStrategy(CompressionOptions opts)Map high-level `CompressionStrategy` to zlib strategy flags.
private fnint gzipWindowBitsForCompress(CompressionOptions opts)Returns zlib windowBits for creating a GZIP stream with deflateInit2.
private fnint gzipWindowBitsForDecompress(DecompressionOptions opts)Returns zlib windowBits for inflating gzip/zlib/deflate with auto-detection enabled.
fnCompressor makeGzipStdZlibCompressor(CompressionOptions opts)Factory function that constructs a `GzipStdZlibCompressor`.
fnDecompressor makeGzipStdZlibDecompressor(DecompressionOptions opts)Factory function that constructs a `GzipStdZlibDecompressor`.