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