Chris@4: (* zlibpas -- Pascal interface to the zlib data compression library Chris@4: * Chris@4: * Copyright (C) 2003 Cosmin Truta. Chris@4: * Derived from original sources by Bob Dellaca. Chris@4: * For conditions of distribution and use, see copyright notice in readme.txt Chris@4: *) Chris@4: Chris@4: unit zlibpas; Chris@4: Chris@4: interface Chris@4: Chris@4: const Chris@4: ZLIB_VERSION = '1.2.7'; Chris@4: ZLIB_VERNUM = $1270; Chris@4: Chris@4: type Chris@4: alloc_func = function(opaque: Pointer; items, size: Integer): Pointer; Chris@4: cdecl; Chris@4: free_func = procedure(opaque, address: Pointer); Chris@4: cdecl; Chris@4: Chris@4: in_func = function(opaque: Pointer; var buf: PByte): Integer; Chris@4: cdecl; Chris@4: out_func = function(opaque: Pointer; buf: PByte; size: Integer): Integer; Chris@4: cdecl; Chris@4: Chris@4: z_streamp = ^z_stream; Chris@4: z_stream = packed record Chris@4: next_in: PChar; (* next input byte *) Chris@4: avail_in: Integer; (* number of bytes available at next_in *) Chris@4: total_in: LongInt; (* total nb of input bytes read so far *) Chris@4: Chris@4: next_out: PChar; (* next output byte should be put there *) Chris@4: avail_out: Integer; (* remaining free space at next_out *) Chris@4: total_out: LongInt; (* total nb of bytes output so far *) Chris@4: Chris@4: msg: PChar; (* last error message, NULL if no error *) Chris@4: state: Pointer; (* not visible by applications *) Chris@4: Chris@4: zalloc: alloc_func; (* used to allocate the internal state *) Chris@4: zfree: free_func; (* used to free the internal state *) Chris@4: opaque: Pointer; (* private data object passed to zalloc and zfree *) Chris@4: Chris@4: data_type: Integer; (* best guess about the data type: ascii or binary *) Chris@4: adler: LongInt; (* adler32 value of the uncompressed data *) Chris@4: reserved: LongInt; (* reserved for future use *) Chris@4: end; Chris@4: Chris@4: gz_headerp = ^gz_header; Chris@4: gz_header = packed record Chris@4: text: Integer; (* true if compressed data believed to be text *) Chris@4: time: LongInt; (* modification time *) Chris@4: xflags: Integer; (* extra flags (not used when writing a gzip file) *) Chris@4: os: Integer; (* operating system *) Chris@4: extra: PChar; (* pointer to extra field or Z_NULL if none *) Chris@4: extra_len: Integer; (* extra field length (valid if extra != Z_NULL) *) Chris@4: extra_max: Integer; (* space at extra (only when reading header) *) Chris@4: name: PChar; (* pointer to zero-terminated file name or Z_NULL *) Chris@4: name_max: Integer; (* space at name (only when reading header) *) Chris@4: comment: PChar; (* pointer to zero-terminated comment or Z_NULL *) Chris@4: comm_max: Integer; (* space at comment (only when reading header) *) Chris@4: hcrc: Integer; (* true if there was or will be a header crc *) Chris@4: done: Integer; (* true when done reading gzip header *) Chris@4: end; Chris@4: Chris@4: (* constants *) Chris@4: const Chris@4: Z_NO_FLUSH = 0; Chris@4: Z_PARTIAL_FLUSH = 1; Chris@4: Z_SYNC_FLUSH = 2; Chris@4: Z_FULL_FLUSH = 3; Chris@4: Z_FINISH = 4; Chris@4: Z_BLOCK = 5; Chris@4: Z_TREES = 6; Chris@4: Chris@4: Z_OK = 0; Chris@4: Z_STREAM_END = 1; Chris@4: Z_NEED_DICT = 2; Chris@4: Z_ERRNO = -1; Chris@4: Z_STREAM_ERROR = -2; Chris@4: Z_DATA_ERROR = -3; Chris@4: Z_MEM_ERROR = -4; Chris@4: Z_BUF_ERROR = -5; Chris@4: Z_VERSION_ERROR = -6; Chris@4: Chris@4: Z_NO_COMPRESSION = 0; Chris@4: Z_BEST_SPEED = 1; Chris@4: Z_BEST_COMPRESSION = 9; Chris@4: Z_DEFAULT_COMPRESSION = -1; Chris@4: Chris@4: Z_FILTERED = 1; Chris@4: Z_HUFFMAN_ONLY = 2; Chris@4: Z_RLE = 3; Chris@4: Z_FIXED = 4; Chris@4: Z_DEFAULT_STRATEGY = 0; Chris@4: Chris@4: Z_BINARY = 0; Chris@4: Z_TEXT = 1; Chris@4: Z_ASCII = 1; Chris@4: Z_UNKNOWN = 2; Chris@4: Chris@4: Z_DEFLATED = 8; Chris@4: Chris@4: (* basic functions *) Chris@4: function zlibVersion: PChar; Chris@4: function deflateInit(var strm: z_stream; level: Integer): Integer; Chris@4: function deflate(var strm: z_stream; flush: Integer): Integer; Chris@4: function deflateEnd(var strm: z_stream): Integer; Chris@4: function inflateInit(var strm: z_stream): Integer; Chris@4: function inflate(var strm: z_stream; flush: Integer): Integer; Chris@4: function inflateEnd(var strm: z_stream): Integer; Chris@4: Chris@4: (* advanced functions *) Chris@4: function deflateInit2(var strm: z_stream; level, method, windowBits, Chris@4: memLevel, strategy: Integer): Integer; Chris@4: function deflateSetDictionary(var strm: z_stream; const dictionary: PChar; Chris@4: dictLength: Integer): Integer; Chris@4: function deflateCopy(var dest, source: z_stream): Integer; Chris@4: function deflateReset(var strm: z_stream): Integer; Chris@4: function deflateParams(var strm: z_stream; level, strategy: Integer): Integer; Chris@4: function deflateTune(var strm: z_stream; good_length, max_lazy, nice_length, max_chain: Integer): Integer; Chris@4: function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt; Chris@4: function deflatePending(var strm: z_stream; var pending: Integer; var bits: Integer): Integer; Chris@4: function deflatePrime(var strm: z_stream; bits, value: Integer): Integer; Chris@4: function deflateSetHeader(var strm: z_stream; head: gz_header): Integer; Chris@4: function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; Chris@4: function inflateSetDictionary(var strm: z_stream; const dictionary: PChar; Chris@4: dictLength: Integer): Integer; Chris@4: function inflateSync(var strm: z_stream): Integer; Chris@4: function inflateCopy(var dest, source: z_stream): Integer; Chris@4: function inflateReset(var strm: z_stream): Integer; Chris@4: function inflateReset2(var strm: z_stream; windowBits: Integer): Integer; Chris@4: function inflatePrime(var strm: z_stream; bits, value: Integer): Integer; Chris@4: function inflateMark(var strm: z_stream): LongInt; Chris@4: function inflateGetHeader(var strm: z_stream; var head: gz_header): Integer; Chris@4: function inflateBackInit(var strm: z_stream; Chris@4: windowBits: Integer; window: PChar): Integer; Chris@4: function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer; Chris@4: out_fn: out_func; out_desc: Pointer): Integer; Chris@4: function inflateBackEnd(var strm: z_stream): Integer; Chris@4: function zlibCompileFlags: LongInt; Chris@4: Chris@4: (* utility functions *) Chris@4: function compress(dest: PChar; var destLen: LongInt; Chris@4: const source: PChar; sourceLen: LongInt): Integer; Chris@4: function compress2(dest: PChar; var destLen: LongInt; Chris@4: const source: PChar; sourceLen: LongInt; Chris@4: level: Integer): Integer; Chris@4: function compressBound(sourceLen: LongInt): LongInt; Chris@4: function uncompress(dest: PChar; var destLen: LongInt; Chris@4: const source: PChar; sourceLen: LongInt): Integer; Chris@4: Chris@4: (* checksum functions *) Chris@4: function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt; Chris@4: function adler32_combine(adler1, adler2, len2: LongInt): LongInt; Chris@4: function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt; Chris@4: function crc32_combine(crc1, crc2, len2: LongInt): LongInt; Chris@4: Chris@4: (* various hacks, don't look :) *) Chris@4: function deflateInit_(var strm: z_stream; level: Integer; Chris@4: const version: PChar; stream_size: Integer): Integer; Chris@4: function inflateInit_(var strm: z_stream; const version: PChar; Chris@4: stream_size: Integer): Integer; Chris@4: function deflateInit2_(var strm: z_stream; Chris@4: level, method, windowBits, memLevel, strategy: Integer; Chris@4: const version: PChar; stream_size: Integer): Integer; Chris@4: function inflateInit2_(var strm: z_stream; windowBits: Integer; Chris@4: const version: PChar; stream_size: Integer): Integer; Chris@4: function inflateBackInit_(var strm: z_stream; Chris@4: windowBits: Integer; window: PChar; Chris@4: const version: PChar; stream_size: Integer): Integer; Chris@4: Chris@4: Chris@4: implementation Chris@4: Chris@4: {$L adler32.obj} Chris@4: {$L compress.obj} Chris@4: {$L crc32.obj} Chris@4: {$L deflate.obj} Chris@4: {$L infback.obj} Chris@4: {$L inffast.obj} Chris@4: {$L inflate.obj} Chris@4: {$L inftrees.obj} Chris@4: {$L trees.obj} Chris@4: {$L uncompr.obj} Chris@4: {$L zutil.obj} Chris@4: Chris@4: function adler32; external; Chris@4: function adler32_combine; external; Chris@4: function compress; external; Chris@4: function compress2; external; Chris@4: function compressBound; external; Chris@4: function crc32; external; Chris@4: function crc32_combine; external; Chris@4: function deflate; external; Chris@4: function deflateBound; external; Chris@4: function deflateCopy; external; Chris@4: function deflateEnd; external; Chris@4: function deflateInit_; external; Chris@4: function deflateInit2_; external; Chris@4: function deflateParams; external; Chris@4: function deflatePending; external; Chris@4: function deflatePrime; external; Chris@4: function deflateReset; external; Chris@4: function deflateSetDictionary; external; Chris@4: function deflateSetHeader; external; Chris@4: function deflateTune; external; Chris@4: function inflate; external; Chris@4: function inflateBack; external; Chris@4: function inflateBackEnd; external; Chris@4: function inflateBackInit_; external; Chris@4: function inflateCopy; external; Chris@4: function inflateEnd; external; Chris@4: function inflateGetHeader; external; Chris@4: function inflateInit_; external; Chris@4: function inflateInit2_; external; Chris@4: function inflateMark; external; Chris@4: function inflatePrime; external; Chris@4: function inflateReset; external; Chris@4: function inflateReset2; external; Chris@4: function inflateSetDictionary; external; Chris@4: function inflateSync; external; Chris@4: function uncompress; external; Chris@4: function zlibCompileFlags; external; Chris@4: function zlibVersion; external; Chris@4: Chris@4: function deflateInit(var strm: z_stream; level: Integer): Integer; Chris@4: begin Chris@4: Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream)); Chris@4: end; Chris@4: Chris@4: function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel, Chris@4: strategy: Integer): Integer; Chris@4: begin Chris@4: Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy, Chris@4: ZLIB_VERSION, sizeof(z_stream)); Chris@4: end; Chris@4: Chris@4: function inflateInit(var strm: z_stream): Integer; Chris@4: begin Chris@4: Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream)); Chris@4: end; Chris@4: Chris@4: function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; Chris@4: begin Chris@4: Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream)); Chris@4: end; Chris@4: Chris@4: function inflateBackInit(var strm: z_stream; Chris@4: windowBits: Integer; window: PChar): Integer; Chris@4: begin Chris@4: Result := inflateBackInit_(strm, windowBits, window, Chris@4: ZLIB_VERSION, sizeof(z_stream)); Chris@4: end; Chris@4: Chris@4: function _malloc(Size: Integer): Pointer; cdecl; Chris@4: begin Chris@4: GetMem(Result, Size); Chris@4: end; Chris@4: Chris@4: procedure _free(Block: Pointer); cdecl; Chris@4: begin Chris@4: FreeMem(Block); Chris@4: end; Chris@4: Chris@4: procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl; Chris@4: begin Chris@4: FillChar(P^, count, B); Chris@4: end; Chris@4: Chris@4: procedure _memcpy(dest, source: Pointer; count: Integer); cdecl; Chris@4: begin Chris@4: Move(source^, dest^, count); Chris@4: end; Chris@4: Chris@4: end.