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").
Copyright
Module Initializers 1
()Types 2
GZIP compressor that implements ddn.api.compressor.Compressor using zlib's deflate with GZIP container (via deflateInit2 and windowBits = 16 + window size).
private CompressionOptions _optsprivate OutputSink _sinkprivate bool _finishedprivate z_stream _zsprivate ubyte[] _outBufprivate bool _initedprivate bool _dictSetvoid setOutputSink(OutputSink sink)Set the output sink delegate that will receive produced compressed chunks.void setProgressCallback(ProgressCallback callback)Set an optional progress callback.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 -> ZFULLFLUSHvoid 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.this(CompressionOptions opts)Create a compressor with provided options.~thisEnsure zlib stream is ended.GZIP decompressor that implements ddn.api.compressor.Decompressor using zlib's inflate with auto header detection (windowBits = 15 + 32).
private DecompressionOptions _optsprivate OutputSink _sinkprivate bool _finishedprivate z_stream _zsprivate ubyte[] _outBufprivate bool _initedprivate bool _needDictprivate bool _sawStreamEndvoid setOutputSink(OutputSink sink)Set the output sink delegate that will receive produced decompressed chunks.void setProgressCallback(ProgressCallback callback)Set an optional progress callback.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.this(DecompressionOptions opts)Create a decompressor with provided options.~thisEnsure zlib stream is ended.Functions 6
int toZLevel(CompressionOptions opts)Map high-level `CompressionLevel`/numericLevel to zlib level (0..9 or ZDEFAULTCOMPRESSION).int toZStrategy(CompressionOptions opts)Map high-level `CompressionStrategy` to zlib strategy flags.int gzipWindowBitsForCompress(CompressionOptions opts)Returns zlib windowBits for creating a GZIP stream with deflateInit2.int gzipWindowBitsForDecompress(DecompressionOptions opts)Returns zlib windowBits for inflating gzip/zlib/deflate with auto-detection enabled.Compressor makeGzipStdZlibCompressor(CompressionOptions opts)Factory function that constructs a `GzipStdZlibCompressor`.Decompressor makeGzipStdZlibDecompressor(DecompressionOptions opts)Factory function that constructs a `GzipStdZlibDecompressor`.