1 (* zlibpas -- Pascal interface to the zlib data compression library
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
13 ZLIB_VERSION = '1.2.5.1';
16 alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
18 free_func = procedure(opaque, address: Pointer);
21 in_func = function(opaque: Pointer; var buf: PByte): Integer;
23 out_func = function(opaque: Pointer; buf: PByte; size: Integer): Integer;
26 z_streamp = ^z_stream;
27 z_stream = packed record
28 next_in: PChar; (* next input byte *)
29 avail_in: Integer; (* number of bytes available at next_in *)
30 total_in: LongInt; (* total nb of input bytes read so far *)
32 next_out: PChar; (* next output byte should be put there *)
33 avail_out: Integer; (* remaining free space at next_out *)
34 total_out: LongInt; (* total nb of bytes output so far *)
36 msg: PChar; (* last error message, NULL if no error *)
37 state: Pointer; (* not visible by applications *)
39 zalloc: alloc_func; (* used to allocate the internal state *)
40 zfree: free_func; (* used to free the internal state *)
41 opaque: Pointer; (* private data object passed to zalloc and zfree *)
43 data_type: Integer; (* best guess about the data type: ascii or binary *)
44 adler: LongInt; (* adler32 value of the uncompressed data *)
45 reserved: LongInt; (* reserved for future use *)
68 Z_BEST_COMPRESSION = 9;
69 Z_DEFAULT_COMPRESSION = -1;
74 Z_DEFAULT_STRATEGY = 0;
83 function zlibVersion: PChar;
84 function deflateInit(var strm: z_stream; level: Integer): Integer;
85 function deflate(var strm: z_stream; flush: Integer): Integer;
86 function deflateEnd(var strm: z_stream): Integer;
87 function inflateInit(var strm: z_stream): Integer;
88 function inflate(var strm: z_stream; flush: Integer): Integer;
89 function inflateEnd(var strm: z_stream): Integer;
91 (* advanced functions *)
92 function deflateInit2(var strm: z_stream; level, method, windowBits,
93 memLevel, strategy: Integer): Integer;
94 function deflateSetDictionary(var strm: z_stream; const dictionary: PChar;
95 dictLength: Integer): Integer;
96 function deflateCopy(var dest, source: z_stream): Integer;
97 function deflateReset(var strm: z_stream): Integer;
98 function deflateParams(var strm: z_stream; level, strategy: Integer): Integer;
99 function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt;
100 function deflatePending(var strm: z_stream; var pending: Integer; var bits: Integer): Integer;
101 function deflatePrime(var strm: z_stream; bits, value: Integer): Integer;
102 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
103 function inflateSetDictionary(var strm: z_stream; const dictionary: PChar;
104 dictLength: Integer): Integer;
105 function inflateSync(var strm: z_stream): Integer;
106 function inflateCopy(var dest, source: z_stream): Integer;
107 function inflateReset(var strm: z_stream): Integer;
108 function inflateBackInit(var strm: z_stream;
109 windowBits: Integer; window: PChar): Integer;
110 function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer;
111 out_fn: out_func; out_desc: Pointer): Integer;
112 function inflateBackEnd(var strm: z_stream): Integer;
113 function zlibCompileFlags: LongInt;
115 (* utility functions *)
116 function compress(dest: PChar; var destLen: LongInt;
117 const source: PChar; sourceLen: LongInt): Integer;
118 function compress2(dest: PChar; var destLen: LongInt;
119 const source: PChar; sourceLen: LongInt;
120 level: Integer): Integer;
121 function compressBound(sourceLen: LongInt): LongInt;
122 function uncompress(dest: PChar; var destLen: LongInt;
123 const source: PChar; sourceLen: LongInt): Integer;
125 (* checksum functions *)
126 function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt;
127 function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt;
129 (* various hacks, don't look :) *)
130 function deflateInit_(var strm: z_stream; level: Integer;
131 const version: PChar; stream_size: Integer): Integer;
132 function inflateInit_(var strm: z_stream; const version: PChar;
133 stream_size: Integer): Integer;
134 function deflateInit2_(var strm: z_stream;
135 level, method, windowBits, memLevel, strategy: Integer;
136 const version: PChar; stream_size: Integer): Integer;
137 function inflateInit2_(var strm: z_stream; windowBits: Integer;
138 const version: PChar; stream_size: Integer): Integer;
139 function inflateBackInit_(var strm: z_stream;
140 windowBits: Integer; window: PChar;
141 const version: PChar; stream_size: Integer): Integer;
158 function adler32; external;
159 function compress; external;
160 function compress2; external;
161 function compressBound; external;
162 function crc32; external;
163 function deflate; external;
164 function deflateBound; external;
165 function deflateCopy; external;
166 function deflateEnd; external;
167 function deflateInit_; external;
168 function deflateInit2_; external;
169 function deflateParams; external;
170 function deflatePending; external;
171 function deflatePrime; external;
172 function deflateReset; external;
173 function deflateSetDictionary; external;
174 function inflate; external;
175 function inflateBack; external;
176 function inflateBackEnd; external;
177 function inflateBackInit_; external;
178 function inflateCopy; external;
179 function inflateEnd; external;
180 function inflateInit_; external;
181 function inflateInit2_; external;
182 function inflateReset; external;
183 function inflateSetDictionary; external;
184 function inflateSync; external;
185 function uncompress; external;
186 function zlibCompileFlags; external;
187 function zlibVersion; external;
189 function deflateInit(var strm: z_stream; level: Integer): Integer;
191 Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream));
194 function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel,
195 strategy: Integer): Integer;
197 Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
198 ZLIB_VERSION, sizeof(z_stream));
201 function inflateInit(var strm: z_stream): Integer;
203 Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream));
206 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
208 Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream));
211 function inflateBackInit(var strm: z_stream;
212 windowBits: Integer; window: PChar): Integer;
214 Result := inflateBackInit_(strm, windowBits, window,
215 ZLIB_VERSION, sizeof(z_stream));
218 function _malloc(Size: Integer): Pointer; cdecl;
220 GetMem(Result, Size);
223 procedure _free(Block: Pointer); cdecl;
228 procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl;
230 FillChar(P^, count, B);
233 procedure _memcpy(dest, source: Pointer; count: Integer); cdecl;
235 Move(source^, dest^, count);