| 1 | 
 (* zlibpas -- Pascal interface to the zlib data compression library | 
 
 
 
 
 
 | 2 | 
  * | 
 
 
 
 
 
 | 3 | 
  * Copyright (C) 2003 Cosmin Truta. | 
 
 
 
 
 
 | 4 | 
  * Derived from original sources by Bob Dellaca. | 
 
 
 
 
 
 | 5 | 
  * For conditions of distribution and use, see copyright notice in readme.txt | 
 
 
 
 
 
 | 6 | 
  *) | 
 
 
 
 
 
 | 7 | 
  | 
 
 
 
 
 
 | 8 | 
 unit zlibpas; | 
 
 
 
 
 
 | 9 | 
  | 
 
 
 
 
 
 | 10 | 
 interface | 
 
 
 
 
 
 | 11 | 
  | 
 
 
 
 
 
 | 12 | 
 const | 
 
 
 
 
 
 | 13 | 
   ZLIB_VERSION = '1.2.8'; | 
 
 
 
 
 
 | 14 | 
   ZLIB_VERNUM  = $1280; | 
 
 
 
 
 
 | 15 | 
  | 
 
 
 
 
 
 | 16 | 
 type | 
 
 
 
 
 
 | 17 | 
   alloc_func = function(opaque: Pointer; items, size: Integer): Pointer; | 
 
 
 
 
 
 | 18 | 
                  cdecl; | 
 
 
 
 
 
 | 19 | 
   free_func  = procedure(opaque, address: Pointer); | 
 
 
 
 
 
 | 20 | 
                  cdecl; | 
 
 
 
 
 
 | 21 | 
  | 
 
 
 
 
 
 | 22 | 
   in_func    = function(opaque: Pointer; var buf: PByte): Integer; | 
 
 
 
 
 
 | 23 | 
                  cdecl; | 
 
 
 
 
 
 | 24 | 
   out_func   = function(opaque: Pointer; buf: PByte; size: Integer): Integer; | 
 
 
 
 
 
 | 25 | 
                  cdecl; | 
 
 
 
 
 
 | 26 | 
  | 
 
 
 
 
 
 | 27 | 
   z_streamp = ^z_stream; | 
 
 
 
 
 
 | 28 | 
   z_stream = packed record | 
 
 
 
 
 
 | 29 | 
     next_in: PChar;       (* next input byte *) | 
 
 
 
 
 
 | 30 | 
     avail_in: Integer;    (* number of bytes available at next_in *) | 
 
 
 
 
 
 | 31 | 
     total_in: LongInt;    (* total nb of input bytes read so far *) | 
 
 
 
 
 
 | 32 | 
  | 
 
 
 
 
 
 | 33 | 
     next_out: PChar;      (* next output byte should be put there *) | 
 
 
 
 
 
 | 34 | 
     avail_out: Integer;   (* remaining free space at next_out *) | 
 
 
 
 
 
 | 35 | 
     total_out: LongInt;   (* total nb of bytes output so far *) | 
 
 
 
 
 
 | 36 | 
  | 
 
 
 
 
 
 | 37 | 
     msg: PChar;           (* last error message, NULL if no error *) | 
 
 
 
 
 
 | 38 | 
     state: Pointer;       (* not visible by applications *) | 
 
 
 
 
 
 | 39 | 
  | 
 
 
 
 
 
 | 40 | 
     zalloc: alloc_func;   (* used to allocate the internal state *) | 
 
 
 
 
 
 | 41 | 
     zfree: free_func;     (* used to free the internal state *) | 
 
 
 
 
 
 | 42 | 
     opaque: Pointer;      (* private data object passed to zalloc and zfree *) | 
 
 
 
 
 
 | 43 | 
  | 
 
 
 
 
 
 | 44 | 
     data_type: Integer;   (* best guess about the data type: ascii or binary *) | 
 
 
 
 
 
 | 45 | 
     adler: LongInt;       (* adler32 value of the uncompressed data *) | 
 
 
 
 
 
 | 46 | 
     reserved: LongInt;    (* reserved for future use *) | 
 
 
 
 
 
 | 47 | 
   end; | 
 
 
 
 
 
 | 48 | 
  | 
 
 
 
 
 
 | 49 | 
   gz_headerp = ^gz_header; | 
 
 
 
 
 
 | 50 | 
   gz_header = packed record | 
 
 
 
 
 
 | 51 | 
     text: Integer;        (* true if compressed data believed to be text *) | 
 
 
 
 
 
 | 52 | 
     time: LongInt;        (* modification time *) | 
 
 
 
 
 
 | 53 | 
     xflags: Integer;      (* extra flags (not used when writing a gzip file) *) | 
 
 
 
 
 
 | 54 | 
     os: Integer;          (* operating system *) | 
 
 
 
 
 
 | 55 | 
     extra: PChar;         (* pointer to extra field or Z_NULL if none *) | 
 
 
 
 
 
 | 56 | 
     extra_len: Integer;   (* extra field length (valid if extra != Z_NULL) *) | 
 
 
 
 
 
 | 57 | 
     extra_max: Integer;   (* space at extra (only when reading header) *) | 
 
 
 
 
 
 | 58 | 
     name: PChar;          (* pointer to zero-terminated file name or Z_NULL *) | 
 
 
 
 
 
 | 59 | 
     name_max: Integer;    (* space at name (only when reading header) *) | 
 
 
 
 
 
 | 60 | 
     comment: PChar;       (* pointer to zero-terminated comment or Z_NULL *) | 
 
 
 
 
 
 | 61 | 
     comm_max: Integer;    (* space at comment (only when reading header) *) | 
 
 
 
 
 
 | 62 | 
     hcrc: Integer;        (* true if there was or will be a header crc *) | 
 
 
 
 
 
 | 63 | 
     done: Integer;        (* true when done reading gzip header *) | 
 
 
 
 
 
 | 64 | 
   end; | 
 
 
 
 
 
 | 65 | 
  | 
 
 
 
 
 
 | 66 | 
 (* constants *) | 
 
 
 
 
 
 | 67 | 
 const | 
 
 
 
 
 
 | 68 | 
   Z_NO_FLUSH      = 0; | 
 
 
 
 
 
 | 69 | 
   Z_PARTIAL_FLUSH = 1; | 
 
 
 
 
 
 | 70 | 
   Z_SYNC_FLUSH    = 2; | 
 
 
 
 
 
 | 71 | 
   Z_FULL_FLUSH    = 3; | 
 
 
 
 
 
 | 72 | 
   Z_FINISH        = 4; | 
 
 
 
 
 
 | 73 | 
   Z_BLOCK         = 5; | 
 
 
 
 
 
 | 74 | 
   Z_TREES         = 6; | 
 
 
 
 
 
 | 75 | 
  | 
 
 
 
 
 
 | 76 | 
   Z_OK            =  0; | 
 
 
 
 
 
 | 77 | 
   Z_STREAM_END    =  1; | 
 
 
 
 
 
 | 78 | 
   Z_NEED_DICT     =  2; | 
 
 
 
 
 
 | 79 | 
   Z_ERRNO         = -1; | 
 
 
 
 
 
 | 80 | 
   Z_STREAM_ERROR  = -2; | 
 
 
 
 
 
 | 81 | 
   Z_DATA_ERROR    = -3; | 
 
 
 
 
 
 | 82 | 
   Z_MEM_ERROR     = -4; | 
 
 
 
 
 
 | 83 | 
   Z_BUF_ERROR     = -5; | 
 
 
 
 
 
 | 84 | 
   Z_VERSION_ERROR = -6; | 
 
 
 
 
 
 | 85 | 
  | 
 
 
 
 
 
 | 86 | 
   Z_NO_COMPRESSION       =  0; | 
 
 
 
 
 
 | 87 | 
   Z_BEST_SPEED           =  1; | 
 
 
 
 
 
 | 88 | 
   Z_BEST_COMPRESSION     =  9; | 
 
 
 
 
 
 | 89 | 
   Z_DEFAULT_COMPRESSION  = -1; | 
 
 
 
 
 
 | 90 | 
  | 
 
 
 
 
 
 | 91 | 
   Z_FILTERED            = 1; | 
 
 
 
 
 
 | 92 | 
   Z_HUFFMAN_ONLY        = 2; | 
 
 
 
 
 
 | 93 | 
   Z_RLE                 = 3; | 
 
 
 
 
 
 | 94 | 
   Z_FIXED               = 4; | 
 
 
 
 
 
 | 95 | 
   Z_DEFAULT_STRATEGY    = 0; | 
 
 
 
 
 
 | 96 | 
  | 
 
 
 
 
 
 | 97 | 
   Z_BINARY   = 0; | 
 
 
 
 
 
 | 98 | 
   Z_TEXT     = 1; | 
 
 
 
 
 
 | 99 | 
   Z_ASCII    = 1; | 
 
 
 
 
 
 | 100 | 
   Z_UNKNOWN  = 2; | 
 
 
 
 
 
 | 101 | 
  | 
 
 
 
 
 
 | 102 | 
   Z_DEFLATED = 8; | 
 
 
 
 
 
 | 103 | 
  | 
 
 
 
 
 
 | 104 | 
 (* basic functions *) | 
 
 
 
 
 
 | 105 | 
 function zlibVersion: PChar; | 
 
 
 
 
 
 | 106 | 
 function deflateInit(var strm: z_stream; level: Integer): Integer; | 
 
 
 
 
 
 | 107 | 
 function deflate(var strm: z_stream; flush: Integer): Integer; | 
 
 
 
 
 
 | 108 | 
 function deflateEnd(var strm: z_stream): Integer; | 
 
 
 
 
 
 | 109 | 
 function inflateInit(var strm: z_stream): Integer; | 
 
 
 
 
 
 | 110 | 
 function inflate(var strm: z_stream; flush: Integer): Integer; | 
 
 
 
 
 
 | 111 | 
 function inflateEnd(var strm: z_stream): Integer; | 
 
 
 
 
 
 | 112 | 
  | 
 
 
 
 
 
 | 113 | 
 (* advanced functions *) | 
 
 
 
 
 
 | 114 | 
 function deflateInit2(var strm: z_stream; level, method, windowBits, | 
 
 
 
 
 
 | 115 | 
                       memLevel, strategy: Integer): Integer; | 
 
 
 
 
 
 | 116 | 
 function deflateSetDictionary(var strm: z_stream; const dictionary: PChar; | 
 
 
 
 
 
 | 117 | 
                               dictLength: Integer): Integer; | 
 
 
 
 
 
 | 118 | 
 function deflateCopy(var dest, source: z_stream): Integer; | 
 
 
 
 
 
 | 119 | 
 function deflateReset(var strm: z_stream): Integer; | 
 
 
 
 
 
 | 120 | 
 function deflateParams(var strm: z_stream; level, strategy: Integer): Integer; | 
 
 
 
 
 
 | 121 | 
 function deflateTune(var strm: z_stream; good_length, max_lazy, nice_length, max_chain: Integer): Integer; | 
 
 
 
 
 
 | 122 | 
 function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt; | 
 
 
 
 
 
 | 123 | 
 function deflatePending(var strm: z_stream; var pending: Integer; var bits: Integer): Integer; | 
 
 
 
 
 
 | 124 | 
 function deflatePrime(var strm: z_stream; bits, value: Integer): Integer; | 
 
 
 
 
 
 | 125 | 
 function deflateSetHeader(var strm: z_stream; head: gz_header): Integer; | 
 
 
 
 
 
 | 126 | 
 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; | 
 
 
 
 
 
 | 127 | 
 function inflateSetDictionary(var strm: z_stream; const dictionary: PChar; | 
 
 
 
 
 
 | 128 | 
                               dictLength: Integer): Integer; | 
 
 
 
 
 
 | 129 | 
 function inflateSync(var strm: z_stream): Integer; | 
 
 
 
 
 
 | 130 | 
 function inflateCopy(var dest, source: z_stream): Integer; | 
 
 
 
 
 
 | 131 | 
 function inflateReset(var strm: z_stream): Integer; | 
 
 
 
 
 
 | 132 | 
 function inflateReset2(var strm: z_stream; windowBits: Integer): Integer; | 
 
 
 
 
 
 | 133 | 
 function inflatePrime(var strm: z_stream; bits, value: Integer): Integer; | 
 
 
 
 
 
 | 134 | 
 function inflateMark(var strm: z_stream): LongInt; | 
 
 
 
 
 
 | 135 | 
 function inflateGetHeader(var strm: z_stream; var head: gz_header): Integer; | 
 
 
 
 
 
 | 136 | 
 function inflateBackInit(var strm: z_stream; | 
 
 
 
 
 
 | 137 | 
                          windowBits: Integer; window: PChar): Integer; | 
 
 
 
 
 
 | 138 | 
 function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer; | 
 
 
 
 
 
 | 139 | 
                      out_fn: out_func; out_desc: Pointer): Integer; | 
 
 
 
 
 
 | 140 | 
 function inflateBackEnd(var strm: z_stream): Integer; | 
 
 
 
 
 
 | 141 | 
 function zlibCompileFlags: LongInt; | 
 
 
 
 
 
 | 142 | 
  | 
 
 
 
 
 
 | 143 | 
 (* utility functions *) | 
 
 
 
 
 
 | 144 | 
 function compress(dest: PChar; var destLen: LongInt; | 
 
 
 
 
 
 | 145 | 
                   const source: PChar; sourceLen: LongInt): Integer; | 
 
 
 
 
 
 | 146 | 
 function compress2(dest: PChar; var destLen: LongInt; | 
 
 
 
 
 
 | 147 | 
                   const source: PChar; sourceLen: LongInt; | 
 
 
 
 
 
 | 148 | 
                   level: Integer): Integer; | 
 
 
 
 
 
 | 149 | 
 function compressBound(sourceLen: LongInt): LongInt; | 
 
 
 
 
 
 | 150 | 
 function uncompress(dest: PChar; var destLen: LongInt; | 
 
 
 
 
 
 | 151 | 
                     const source: PChar; sourceLen: LongInt): Integer; | 
 
 
 
 
 
 | 152 | 
  | 
 
 
 
 
 
 | 153 | 
 (* checksum functions *) | 
 
 
 
 
 
 | 154 | 
 function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt; | 
 
 
 
 
 
 | 155 | 
 function adler32_combine(adler1, adler2, len2: LongInt): LongInt; | 
 
 
 
 
 
 | 156 | 
 function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt; | 
 
 
 
 
 
 | 157 | 
 function crc32_combine(crc1, crc2, len2: LongInt): LongInt; | 
 
 
 
 
 
 | 158 | 
  | 
 
 
 
 
 
 | 159 | 
 (* various hacks, don't look :) *) | 
 
 
 
 
 
 | 160 | 
 function deflateInit_(var strm: z_stream; level: Integer; | 
 
 
 
 
 
 | 161 | 
                       const version: PChar; stream_size: Integer): Integer; | 
 
 
 
 
 
 | 162 | 
 function inflateInit_(var strm: z_stream; const version: PChar; | 
 
 
 
 
 
 | 163 | 
                       stream_size: Integer): Integer; | 
 
 
 
 
 
 | 164 | 
 function deflateInit2_(var strm: z_stream; | 
 
 
 
 
 
 | 165 | 
                        level, method, windowBits, memLevel, strategy: Integer; | 
 
 
 
 
 
 | 166 | 
                        const version: PChar; stream_size: Integer): Integer; | 
 
 
 
 
 
 | 167 | 
 function inflateInit2_(var strm: z_stream; windowBits: Integer; | 
 
 
 
 
 
 | 168 | 
                        const version: PChar; stream_size: Integer): Integer; | 
 
 
 
 
 
 | 169 | 
 function inflateBackInit_(var strm: z_stream; | 
 
 
 
 
 
 | 170 | 
                           windowBits: Integer; window: PChar; | 
 
 
 
 
 
 | 171 | 
                           const version: PChar; stream_size: Integer): Integer; | 
 
 
 
 
 
 | 172 | 
  | 
 
 
 
 
 
 | 173 | 
  | 
 
 
 
 
 
 | 174 | 
 implementation | 
 
 
 
 
 
 | 175 | 
  | 
 
 
 
 
 
 | 176 | 
 {$L adler32.obj} | 
 
 
 
 
 
 | 177 | 
 {$L compress.obj} | 
 
 
 
 
 
 | 178 | 
 {$L crc32.obj} | 
 
 
 
 
 
 | 179 | 
 {$L deflate.obj} | 
 
 
 
 
 
 | 180 | 
 {$L infback.obj} | 
 
 
 
 
 
 | 181 | 
 {$L inffast.obj} | 
 
 
 
 
 
 | 182 | 
 {$L inflate.obj} | 
 
 
 
 
 
 | 183 | 
 {$L inftrees.obj} | 
 
 
 
 
 
 | 184 | 
 {$L trees.obj} | 
 
 
 
 
 
 | 185 | 
 {$L uncompr.obj} | 
 
 
 
 
 
 | 186 | 
 {$L zutil.obj} | 
 
 
 
 
 
 | 187 | 
  | 
 
 
 
 
 
 | 188 | 
 function adler32; external; | 
 
 
 
 
 
 | 189 | 
 function adler32_combine; external; | 
 
 
 
 
 
 | 190 | 
 function compress; external; | 
 
 
 
 
 
 | 191 | 
 function compress2; external; | 
 
 
 
 
 
 | 192 | 
 function compressBound; external; | 
 
 
 
 
 
 | 193 | 
 function crc32; external; | 
 
 
 
 
 
 | 194 | 
 function crc32_combine; external; | 
 
 
 
 
 
 | 195 | 
 function deflate; external; | 
 
 
 
 
 
 | 196 | 
 function deflateBound; external; | 
 
 
 
 
 
 | 197 | 
 function deflateCopy; external; | 
 
 
 
 
 
 | 198 | 
 function deflateEnd; external; | 
 
 
 
 
 
 | 199 | 
 function deflateInit_; external; | 
 
 
 
 
 
 | 200 | 
 function deflateInit2_; external; | 
 
 
 
 
 
 | 201 | 
 function deflateParams; external; | 
 
 
 
 
 
 | 202 | 
 function deflatePending; external; | 
 
 
 
 
 
 | 203 | 
 function deflatePrime; external; | 
 
 
 
 
 
 | 204 | 
 function deflateReset; external; | 
 
 
 
 
 
 | 205 | 
 function deflateSetDictionary; external; | 
 
 
 
 
 
 | 206 | 
 function deflateSetHeader; external; | 
 
 
 
 
 
 | 207 | 
 function deflateTune; external; | 
 
 
 
 
 
 | 208 | 
 function inflate; external; | 
 
 
 
 
 
 | 209 | 
 function inflateBack; external; | 
 
 
 
 
 
 | 210 | 
 function inflateBackEnd; external; | 
 
 
 
 
 
 | 211 | 
 function inflateBackInit_; external; | 
 
 
 
 
 
 | 212 | 
 function inflateCopy; external; | 
 
 
 
 
 
 | 213 | 
 function inflateEnd; external; | 
 
 
 
 
 
 | 214 | 
 function inflateGetHeader; external; | 
 
 
 
 
 
 | 215 | 
 function inflateInit_; external; | 
 
 
 
 
 
 | 216 | 
 function inflateInit2_; external; | 
 
 
 
 
 
 | 217 | 
 function inflateMark; external; | 
 
 
 
 
 
 | 218 | 
 function inflatePrime; external; | 
 
 
 
 
 
 | 219 | 
 function inflateReset; external; | 
 
 
 
 
 
 | 220 | 
 function inflateReset2; external; | 
 
 
 
 
 
 | 221 | 
 function inflateSetDictionary; external; | 
 
 
 
 
 
 | 222 | 
 function inflateSync; external; | 
 
 
 
 
 
 | 223 | 
 function uncompress; external; | 
 
 
 
 
 
 | 224 | 
 function zlibCompileFlags; external; | 
 
 
 
 
 
 | 225 | 
 function zlibVersion; external; | 
 
 
 
 
 
 | 226 | 
  | 
 
 
 
 
 
 | 227 | 
 function deflateInit(var strm: z_stream; level: Integer): Integer; | 
 
 
 
 
 
 | 228 | 
 begin | 
 
 
 
 
 
 | 229 | 
   Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream)); | 
 
 
 
 
 
 | 230 | 
 end; | 
 
 
 
 
 
 | 231 | 
  | 
 
 
 
 
 
 | 232 | 
 function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel, | 
 
 
 
 
 
 | 233 | 
                       strategy: Integer): Integer; | 
 
 
 
 
 
 | 234 | 
 begin | 
 
 
 
 
 
 | 235 | 
   Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | 
 
 
 
 
 
 | 236 | 
                           ZLIB_VERSION, sizeof(z_stream)); | 
 
 
 
 
 
 | 237 | 
 end; | 
 
 
 
 
 
 | 238 | 
  | 
 
 
 
 
 
 | 239 | 
 function inflateInit(var strm: z_stream): Integer; | 
 
 
 
 
 
 | 240 | 
 begin | 
 
 
 
 
 
 | 241 | 
   Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream)); | 
 
 
 
 
 
 | 242 | 
 end; | 
 
 
 
 
 
 | 243 | 
  | 
 
 
 
 
 
 | 244 | 
 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; | 
 
 
 
 
 
 | 245 | 
 begin | 
 
 
 
 
 
 | 246 | 
   Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream)); | 
 
 
 
 
 
 | 247 | 
 end; | 
 
 
 
 
 
 | 248 | 
  | 
 
 
 
 
 
 | 249 | 
 function inflateBackInit(var strm: z_stream; | 
 
 
 
 
 
 | 250 | 
                          windowBits: Integer; window: PChar): Integer; | 
 
 
 
 
 
 | 251 | 
 begin | 
 
 
 
 
 
 | 252 | 
   Result := inflateBackInit_(strm, windowBits, window, | 
 
 
 
 
 
 | 253 | 
                              ZLIB_VERSION, sizeof(z_stream)); | 
 
 
 
 
 
 | 254 | 
 end; | 
 
 
 
 
 
 | 255 | 
  | 
 
 
 
 
 
 | 256 | 
 function _malloc(Size: Integer): Pointer; cdecl; | 
 
 
 
 
 
 | 257 | 
 begin | 
 
 
 
 
 
 | 258 | 
   GetMem(Result, Size); | 
 
 
 
 
 
 | 259 | 
 end; | 
 
 
 
 
 
 | 260 | 
  | 
 
 
 
 
 
 | 261 | 
 procedure _free(Block: Pointer); cdecl; | 
 
 
 
 
 
 | 262 | 
 begin | 
 
 
 
 
 
 | 263 | 
   FreeMem(Block); | 
 
 
 
 
 
 | 264 | 
 end; | 
 
 
 
 
 
 | 265 | 
  | 
 
 
 
 
 
 | 266 | 
 procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl; | 
 
 
 
 
 
 | 267 | 
 begin | 
 
 
 
 
 
 | 268 | 
   FillChar(P^, count, B); | 
 
 
 
 
 
 | 269 | 
 end; | 
 
 
 
 
 
 | 270 | 
  | 
 
 
 
 
 
 | 271 | 
 procedure _memcpy(dest, source: Pointer; count: Integer); cdecl; | 
 
 
 
 
 
 | 272 | 
 begin | 
 
 
 
 
 
 | 273 | 
   Move(source^, dest^, count); | 
 
 
 
 
 
 | 274 | 
 end; | 
 
 
 
 
 
 | 275 | 
  | 
 
 
 
 
 
 | 276 | 
 end. |