Unit Zlib

Classes

Functions

Trace - preset dictionary flag in zlib header
Tracec -
Tracecv -
Tracev -
Tracevv -
Tracevvv -
TRY_FREE -
ZALLOC -
zError - The application can compare zlibVersion and ZLIB_VERSION for consistency.
ZFREE -
zlibVersion -

Types

alloc_func
check_func
free_func
huft_field
huft_ptr
inflate_blocks_state
inflate_block_mode
inflate_codes_mode
inflate_codes_state
inflate_huft
inflate_mode
internal_state
pInflate_blocks_state
pInflate_codes_state
pInflate_huft
pInternal_state
ppInflate_huft
z_stream
z_streamp

Constants

DEF_MEM_LEVEL
DEF_WBITS
DYN_TREES
MAX_MATCH
MAX_MEM_LEVEL
MAX_WBITS
MIN_MATCH
PRESET_DICT
STATIC_TREES
STORED_BLOCK
ZLIB_VERSION
Z_ASCII
Z_BEST_COMPRESSION
Z_BEST_SPEED
Z_BINARY
Z_BUF_ERROR
Z_DATA_ERROR
Z_DEFAULT_COMPRESSION
Z_DEFAULT_STRATEGY
Z_DEFLATED
z_errbase
z_errmsg
Z_ERRNO
Z_FILTERED
Z_FINISH
Z_FULL_FLUSH
Z_HUFFMAN_ONLY
Z_MEM_ERROR
Z_NEED_DICT
Z_NO_COMPRESSION
Z_NO_FLUSH
Z_NULL
Z_OK
Z_PARTIAL_FLUSH
Z_STREAM_END
Z_STREAM_ERROR
Z_SYNC_FLUSH
Z_UNKNOWN
z_verbose
Z_VERSION_ERROR

Variables


Functions


procedure Trace(x : string);

preset dictionary flag in zlib header

procedure Tracec(c : boolean; x : string);


procedure Tracecv(c : boolean; x : string);


procedure Tracev(x : string);


procedure Tracevv(x : string);


procedure Tracevvv(x : string);


procedure TRY_FREE (var strm : z_stream; ptr : voidpf);


function ZALLOC (var strm : z_stream; items : uInt; size : uInt) : voidpf;


function zError(err : int) : string;

The application can compare zlibVersion and ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check is automatically made by deflateInit and inflateInit.

procedure ZFREE (var strm : z_stream; ptr : voidpf);


function zlibVersion : string;


Types


alloc_func = function(opaque : voidpf; items : uInt; size : uInt) : voidpf
current inflate_blocks state
check_func = function(check : uLong;
                        buf : pBytef;
                        {const buf : array of byte;}
	                len : uInt) : uLong
distance tree
free_func = procedure(opaque : voidpf; address : voidpf)

huft_field = Array[0..(MaxInt div SizeOf(inflate_huft))-1] of inflate_huft;
literal, length base, or distance base } { or table offset
huft_ptr = ^huft_field

inflate_blocks_state = record
mode : inflate_block_mode;
last : boolean;
bitk : uInt;
bitb : uLong;
hufts : huft_ptr;
window : pBytef;
zend : pBytef;
pBytef : pBytef;
checkfn : check_func;
check : uLong;
end;
inflate blocks semi-private state
inflate_block_mode =
     (ZTYPE,    { get type bits (3, including end bit) }
      LENS,     { get lengths for stored }
      STORED,   { processing stored block }
      TABLE,    { get table lengths }
      BTREE,    { get bit lengths tree for a dynamic block }
      DTREE,    { get length, distance trees for a dynamic block }
      CODES,    { processing fixed or dynamic block }
      DRY,      { output remaining window bytes }
      BLKDONE,  { finished last block, done }
      BLKBAD);
const buf : array of byte;
inflate_codes_mode = ( { waiting for "i:"=input, "o:"=output, "x:"=nothing }
        START,    { x: set up for LEN }
        LEN,      { i: get length/literal/eob next }
        LENEXT,   { i: getting length extra (have base) }
        DIST,     { i: get distance next }
        DISTEXT,  { i: getting distance extra }
        COPY,     { o: copying bytes in window, waiting for space }
        LIT,      { o: got literal, waiting for output space }
        WASH,     { o: got eob, possibly still output waiting }
        ZEND,     { x: got eob and all data flushed }
        BADCODE);

inflate_codes_state = record
mode : inflate_codes_mode;
len : uInt;
lbits : Byte;
dbits : Byte;
ltree : pInflate_huft;
dtree : pInflate_huft;
end;

inflate_huft = record
Exop : Byte;
bits : Byte;
base : uInt;
end;

inflate_mode = (
      METHOD,   { waiting for method byte }
      FLAG,     { waiting for flag byte }
      DICT4,    { four dictionary check bytes to go }
      DICT3,    { three dictionary check bytes to go }
      DICT2,    { two dictionary check bytes to go }
      DICT1,    { one dictionary check byte to go }
      DICT0,    { waiting for inflateSetDictionary }
      BLOCKS,   { decompressing blocks }
      CHECK4,   { four check bytes to go }
      CHECK3,   { three check bytes to go }
      CHECK2,   { two check bytes to go }
      CHECK1,   { one check byte to go }
      DONE,     { finished check, done }
      BAD);
check on output
internal_state = record
mode : inflate_mode;
nowrap : boolean;
wbits : uInt;
blocks : pInflate_blocks_state;
end;
or point to a deflate_state record
pInflate_blocks_state = ^inflate_blocks_state
got a data error--stuck here
pInflate_codes_state = ^inflate_codes_state
x: got error } { inflate codes private state
pInflate_huft = ^inflate_huft
The memory requirements for deflate are (in bytes): 1 shl (windowBits+2) + 1 shl (memLevel+9) that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) plus a few kilobytes for small objects. For example, if you want to reduce the default memory requirements from 256K to 128K, compile with DMAX_WBITS=14 DMAX_MEM_LEVEL=7 Of course this will generally degrade compression (there's no free lunch). The memory requirements for inflate are (in bytes) 1 shl windowBits that is, 32K for windowBits=15 (default value) plus a few kilobytes for small objects. } { Huffman code lookup table entry--this entry is four bytes for machines that have 16-bit pointers (e.g. PC's in the small or medium model).
pInternal_state = ^internal_state
got an error--stay here } { inflate private state
ppInflate_huft = ^pInflate_huft

z_stream = record
next_in : pBytef;
avail_in : uInt;
total_in : uLong;
next_out : pBytef;
avail_out : uInt;
total_out : uLong;
msg : string;
state : pInternal_state;
zalloc : alloc_func;
zfree : free_func;
opaque : voidpf;
data_type : int;
adler : uLong;
reserved : uLong;
end;

z_streamp = ^z_stream

Constants

DEF_MEM_LEVEL = 8

DEF_WBITS = MAX_WBITS

32K LZ77 window } { default windowBits for decompression. MAX_WBITS is for compression only

DYN_TREES = 2

MAX_MATCH = ??

MAX_MEM_LEVEL = 9

zconf.h -- configuration of the zlib compression library } { zutil.c -- target dependent utility functions for the compression library } { The 'zlib' compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data. This version of the library supports only one compression method (deflation) but other algorithms will be added later and will have the same stream interface. Compression can be done in a single step if the buffers are large enough (for example if an input file is mmap'ed), or can be done by repeated calls of the compression function. In the latter case, the application must provide more input and/or consume the output (providing more output space) before each call. The library also supports reading and writing files in gzip (.gz) format with an interface similar to that of stdio. The library does not install any signal handler. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input. } { Compile with -DMAXSEG_64K if the alloc function cannot allocate more than 64k bytes at a time (needed on systems with 16-bit int). } { Maximum value for memLevel in deflateInit2

MAX_WBITS = 15

if MAX_MEM_LEVEL > 8 } {$endif} { Maximum value for windowBits in deflateInit2 and inflateInit2

MIN_MATCH = 3

The minimum and maximum match lengths

PRESET_DICT = $20

deliberate syntax error } {$endif

STATIC_TREES = 1

STORED_BLOCK = 0

for initializing zalloc, zfree, opaque } { common constants } { The three kinds of block type

ZLIB_VERSION = '1.1.2'

Z_ASCII = 1

Z_BEST_COMPRESSION = 9

Z_BEST_SPEED = 1

Z_BINARY = 0

compression strategy; see deflateInit2() below for details

Z_BUF_ERROR = (-5)

Z_DATA_ERROR = (-3)

Z_DEFAULT_COMPRESSION = (-1)

Z_DEFAULT_STRATEGY = 0

Z_DEFLATED = 8

Possible values of the data_type field

z_errbase = Z_NEED_DICT

z_errmsg = { indexed by 2-zlib_error } ('need dictionary', { Z_NEED_DICT 2 } 'stream end', { Z_STREAM_END 1 } '', { Z_OK 0 } 'file error', { Z_ERRNO (-1) } 'stream error', { Z_STREAM_ERROR (-2) } 'data error', { Z_DATA_ERROR (-3) } 'insufficient memory', { Z_MEM_ERROR (-4) } 'buffer error', { Z_BUF_ERROR (-5) } 'incompatible version',{ Z_VERSION_ERROR (-6) } '')

Z_ERRNO = (-1)

Z_FILTERED = 1

compression levels

Z_FINISH = 4

Z_FULL_FLUSH = 3

Z_HUFFMAN_ONLY = 2

Z_MEM_ERROR = (-4)

Z_NEED_DICT = 2

Z_NO_COMPRESSION = 0

Return codes for the compression/decompression functions. Negative values are errors, positive values are used for special but normal events.

Z_NO_FLUSH = 0

constants

Z_NULL = NIL

The deflate compression method (the only one supported in this version)

Z_OK = 0

Allowed flush values; see deflate() below for details

Z_PARTIAL_FLUSH = 1

Z_STREAM_END = 1

Z_STREAM_ERROR = (-2)

Z_SYNC_FLUSH = 2

Z_UNKNOWN = 2

z_verbose = 1

Z_VERSION_ERROR (-6)

Z_VERSION_ERROR = (-6)


Variables