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