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.7';
17
alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
19
free_func = procedure(opaque, address: Pointer);
22
in_func = function(opaque: Pointer; var buf: PByte): Integer;
24
out_func = function(opaque: Pointer; buf: PByte; size: Integer): Integer;
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 *)
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 *)
37
msg: PChar; (* last error message, NULL if no error *)
38
state: Pointer; (* not visible by applications *)
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 *)
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 *)
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 *)
88
Z_BEST_COMPRESSION = 9;
89
Z_DEFAULT_COMPRESSION = -1;
95
Z_DEFAULT_STRATEGY = 0;
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;
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;
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;
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;
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;
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;
227
function deflateInit(var strm: z_stream; level: Integer): Integer;
229
Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream));
232
function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel,
233
strategy: Integer): Integer;
235
Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
236
ZLIB_VERSION, sizeof(z_stream));
239
function inflateInit(var strm: z_stream): Integer;
241
Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream));
244
function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
246
Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream));
249
function inflateBackInit(var strm: z_stream;
250
windowBits: Integer; window: PChar): Integer;
252
Result := inflateBackInit_(strm, windowBits, window,
253
ZLIB_VERSION, sizeof(z_stream));
256
function _malloc(Size: Integer): Pointer; cdecl;
258
GetMem(Result, Size);
261
procedure _free(Block: Pointer); cdecl;
266
procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl;
268
FillChar(P^, count, B);
271
procedure _memcpy(dest, source: Pointer; count: Integer); cdecl;
273
Move(source^, dest^, count);