ddn.compressor.deflate
ddn.compressor.deflate
CompressionProvider 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.
Copyright
BSD-3-Clause
Module Initializers 1
shared static this
()Types 2
classDeflateCompressor : Compressor
DEFLATE compressor using the pure-D zlib engine (ddn.compressor.zlib).
Fields
private CompressionOptions _optsprivate OutputSink _sinkprivate bool _finishedprivate z_stream _zsprivate bool _dictSetprivate ubyte[] _dictionaryprivate ulong _bytesInprivate ulong _bytesOutprivate int _windowBitsMethods
void 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 -> Z_SYNC_FLUSH - full -> Z_FULL_FLUSHvoid 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.classDeflateDecompressor : Decompressor
DEFLATE decompressor using the pure-D zlib engine (ddn.compressor.zlib).
Fields
private DecompressionOptions _optsprivate OutputSink _sinkprivate bool _finishedprivate z_stream _zsprivate bool _dictSetprivate ubyte[] _dictionaryprivate bool _sawStreamEndprivate ulong _bytesInprivate ulong _bytesOutprivate int _windowBitsMethods
void setOutputSink(OutputSink sink)Set the output sink delegate that will receive produced decompressed chunks.void setProgressCallback(ProgressCallback callback)Set an optional progress callback.private
bool applyConfiguredDictionary()Apply the configured dictionary when the inflate stream requests one.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)Configure a dictionary for streams that declare FDICT.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
fn
Compressor makeDeflateCompressor(CompressionOptions opts)Factory function that constructs a `DeflateCompressor`.fn
Decompressor makeDeflateDecompressor(DecompressionOptions opts)Factory function that constructs a `DeflateDecompressor`.