ddn.compressor.zlib

ddn.compressor.zlib

A pure D implementation of the zlib compression library interface. This module provides a drop-in replacement for etc.c.zlib with identical API, implementing the DEFLATE compression algorithm (RFC 1951), zlib format (RFC 1950), and GZIP format (RFC 1952) entirely in D.

Features:

  • Complete DEFLATE compression and decompression
  • Support for raw DEFLATE, zlib, and GZIP container formats
  • Dictionary support for improved compression
  • Streaming API compatible with zlib's z_stream interface
  • Adler-32 and CRC-32 checksum implementations

The implementation follows the zlib API conventions for maximum compatibility with existing code that uses etc.c.zlib.

Module Initializers 1

shared static this()

Types 5

aliasalloc_func = void * function(void * opaque, uint items, uint size)

Callback type for custom memory allocation

aliasfree_func = void function(void * opaque, void * address)

Callback type for custom memory deallocation

structz_stream

The z_stream structure is used to pass information between the application and the compression/decompression library functions.

This structure mirrors the zlib z_stream_s struct for API compatibility.

Fields
ubyte * next_inInput buffer pointer
uint avail_inNumber of bytes available at next_in
c_ulong total_inTotal number of input bytes read so far
ubyte * next_outOutput buffer pointer
uint avail_outRemaining free space at next_out
c_ulong total_outTotal number of bytes output so far
const(char) * msgLast error message, null if no error
void * internalInternal state (opaque to application)
alloc_func zallocCustom allocator function (not used in pure D implementation)
free_func zfreeCustom deallocator function (not used in pure D implementation)
void * opaquePrivate data for custom allocator
int data_typeBest guess about the data type: Z_BINARY or Z_TEXT
c_ulong adlerAdler-32 or CRC-32 checksum value
c_ulong reservedReserved for future use
aliasz_streamp = z_stream *

Pointer to z_stream

aliasc_ulong = size_t

C unsigned long type alias for cross-platform compatibility

Functions 22

fnc_ulong adler32(c_ulong adler, const(ubyte) * buf, uint len) nothrow @trustedCompute the Adler-32 checksum of a data buffer.
fnc_ulong adler32(c_ulong adler, const(ubyte)[] buf) nothrow @trustedditto
fnc_ulong crc32(c_ulong crc, const(ubyte) * buf, uint len) nothrow @trustedCompute the CRC-32 checksum of a data buffer.
fnc_ulong crc32(c_ulong crc, const(ubyte)[] buf) nothrow @trustedditto
fnint deflateInit2_(z_stream * strm, int level, int method, int windowBits, int memLevel, int strategy, const(char) * ver, int streamSize) nothrowInitialize a deflate stream with full parameters.
fnint deflateInit2(z_stream * strm, int level, int method, int windowBits, int memLevel, int strategy) nothrowSimplified deflate initialization.
fnint deflateInit(z_stream * strm, int level) nothrowBasic deflate initialization with default parameters.
fnint deflate(z_stream * strm, int flush) nothrowCompress data.
fnint deflateEnd(z_stream * strm) nothrowFree deflate state and resources.
fnint deflateReset(z_stream * strm) nothrowReset deflate stream to initial state.
fnint deflateSetDictionary(z_stream * strm, const(ubyte) * dictionary, uint dictLength) nothrowSet compression dictionary.
fnint inflateInit2_(z_stream * strm, int windowBits, const(char) * ver, int streamSize) nothrowInitialize an inflate stream with full parameters.
fnint inflateInit2(z_stream * strm, int windowBits) nothrowSimplified inflate initialization.
fnint inflateInit(z_stream * strm) nothrowBasic inflate initialization with default parameters.
fnint inflate(z_stream * strm, int flush) nothrowDecompress data.
fnint inflateEnd(z_stream * strm) nothrowFree inflate state and resources.
fnint inflateReset(z_stream * strm) nothrowReset inflate stream to initial state.
fnint inflateSetDictionary(z_stream * strm, const(ubyte) * dictionary, uint dictLength) nothrowSet decompression dictionary.
fnint compress(ubyte * dest, c_ulong * destLen, const(ubyte) * source, c_ulong sourceLen) nothrowCompress source buffer to destination buffer.
fnint compress2(ubyte * dest, c_ulong * destLen, const(ubyte) * source, c_ulong sourceLen, int level) nothrowCompress source buffer to destination buffer with specified level.
fnint uncompress(ubyte * dest, c_ulong * destLen, const(ubyte) * source, c_ulong sourceLen) nothrowDecompress source buffer to destination buffer.
fnc_ulong compressBound(c_ulong sourceLen) nothrow @safeCalculate upper bound on compressed size.

Variables 32

enumvarZLIB_VERSION = "1.3.1-ddn"

zlib version string for compatibility

enumvarZ_NO_FLUSH = 0

Flush modes for compression/decompression No flush, accumulate output

enumvarZ_PARTIAL_FLUSH = 1

Partial flush (obsolete, use Z_SYNC_FLUSH)

enumvarZ_SYNC_FLUSH = 2

Flush to byte boundary, sync point

enumvarZ_FULL_FLUSH = 3

Flush and reset compression state

enumvarZ_FINISH = 4

Finish the stream

enumvarZ_BLOCK = 5

Stop at next block boundary

enumvarZ_TREES = 6

Request deflate header/trees

enumvarZ_OK = 0

Return codes Success

enumvarZ_STREAM_END = 1

End of stream reached

enumvarZ_NEED_DICT = 2

Dictionary required for decompression

enumvarZ_ERRNO = - 1

File system error

enumvarZ_STREAM_ERROR = - 2

Stream state error

enumvarZ_DATA_ERROR = - 3

Data corrupted

enumvarZ_MEM_ERROR = - 4

Memory allocation failed

enumvarZ_BUF_ERROR = - 5

Buffer too small or no progress possible

enumvarZ_VERSION_ERROR = - 6

zlib version mismatch

enumvarZ_NO_COMPRESSION = 0

Compression levels Store only, no compression

enumvarZ_BEST_SPEED = 1

Fastest compression

enumvarZ_BEST_COMPRESSION = 9

Best compression ratio

enumvarZ_DEFAULT_COMPRESSION = - 1

Default compression level (typically 6)

enumvarZ_DEFAULT_STRATEGY = 0

Compression strategies Normal compression for general data

enumvarZ_FILTERED = 1

Data with random distribution

enumvarZ_HUFFMAN_ONLY = 2

Huffman coding only (no LZ77)

enumvarZ_RLE = 3

Run-length encoding

enumvarZ_FIXED = 4

Use fixed Huffman codes

enumvarZ_DEFLATED = 8

Compression method The deflate compression method

enumvarMAX_WBITS = 15

Window bits range Maximum window bits (32K window)

enumvarMAX_MEM_LEVEL = 9

Memory level range Maximum memory level

enumvarSEEK_SET = 0

Seek modes (for gzip)

enumvarSEEK_CUR = 1
enumvarSEEK_END = 2