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.11';
14 ZLIB_VERNUM = $12a0;
15
16 type
paquenull17 alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
18 cdecl;
19 free_func = procedure(opaque, address: Pointer);
20 cdecl;
21
paquenull22 in_func = function(opaque: Pointer; var buf: PByte): Integer;
23 cdecl;
paquenull24 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 *)
zlibVersionnull105 function zlibVersion: PChar;
deflateInitnull106 function deflateInit(var strm: z_stream; level: Integer): Integer;
deflatenull107 function deflate(var strm: z_stream; flush: Integer): Integer;
deflateEndnull108 function deflateEnd(var strm: z_stream): Integer;
inflateInitnull109 function inflateInit(var strm: z_stream): Integer;
inflatenull110 function inflate(var strm: z_stream; flush: Integer): Integer;
inflateEndnull111 function inflateEnd(var strm: z_stream): Integer;
112
113 (* advanced functions *)
deflateInit2null114 function deflateInit2(var strm: z_stream; level, method, windowBits,
115 memLevel, strategy: Integer): Integer;
deflateSetDictionarynull116 function deflateSetDictionary(var strm: z_stream; const dictionary: PChar;
117 dictLength: Integer): Integer;
deflateCopynull118 function deflateCopy(var dest, source: z_stream): Integer;
deflateResetnull119 function deflateReset(var strm: z_stream): Integer;
deflateParamsnull120 function deflateParams(var strm: z_stream; level, strategy: Integer): Integer;
deflateTunenull121 function deflateTune(var strm: z_stream; good_length, max_lazy, nice_length, max_chain: Integer): Integer;
deflateBoundnull122 function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt;
deflatePendingnull123 function deflatePending(var strm: z_stream; var pending: Integer; var bits: Integer): Integer;
deflatePrimenull124 function deflatePrime(var strm: z_stream; bits, value: Integer): Integer;
deflateSetHeadernull125 function deflateSetHeader(var strm: z_stream; head: gz_header): Integer;
inflateInit2null126 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
inflateSetDictionarynull127 function inflateSetDictionary(var strm: z_stream; const dictionary: PChar;
128 dictLength: Integer): Integer;
inflateSyncnull129 function inflateSync(var strm: z_stream): Integer;
inflateCopynull130 function inflateCopy(var dest, source: z_stream): Integer;
inflateResetnull131 function inflateReset(var strm: z_stream): Integer;
inflateReset2null132 function inflateReset2(var strm: z_stream; windowBits: Integer): Integer;
inflatePrimenull133 function inflatePrime(var strm: z_stream; bits, value: Integer): Integer;
inflateMarknull134 function inflateMark(var strm: z_stream): LongInt;
inflateGetHeadernull135 function inflateGetHeader(var strm: z_stream; var head: gz_header): Integer;
inflateBackInitnull136 function inflateBackInit(var strm: z_stream;
137 windowBits: Integer; window: PChar): Integer;
inflateBacknull138 function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer;
139 out_fn: out_func; out_desc: Pointer): Integer;
inflateBackEndnull140 function inflateBackEnd(var strm: z_stream): Integer;
zlibCompileFlagsnull141 function zlibCompileFlags: LongInt;
142
143 (* utility functions *)
compressnull144 function compress(dest: PChar; var destLen: LongInt;
145 const source: PChar; sourceLen: LongInt): Integer;
compress2null146 function compress2(dest: PChar; var destLen: LongInt;
147 const source: PChar; sourceLen: LongInt;
148 level: Integer): Integer;
compressBoundnull149 function compressBound(sourceLen: LongInt): LongInt;
uncompressnull150 function uncompress(dest: PChar; var destLen: LongInt;
151 const source: PChar; sourceLen: LongInt): Integer;
152
153 (* checksum functions *)
adler32null154 function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt;
adler32_combinenull155 function adler32_combine(adler1, adler2, len2: LongInt): LongInt;
crc32null156 function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt;
crc32_combinenull157 function crc32_combine(crc1, crc2, len2: LongInt): LongInt;
158
159 (* various hacks, don't look :) *)
deflateInit_null160 function deflateInit_(var strm: z_stream; level: Integer;
161 const version: PChar; stream_size: Integer): Integer;
inflateInit_null162 function inflateInit_(var strm: z_stream; const version: PChar;
163 stream_size: Integer): Integer;
deflateInit2_null164 function deflateInit2_(var strm: z_stream;
165 level, method, windowBits, memLevel, strategy: Integer;
166 const version: PChar; stream_size: Integer): Integer;
inflateInit2_null167 function inflateInit2_(var strm: z_stream; windowBits: Integer;
168 const version: PChar; stream_size: Integer): Integer;
inflateBackInit_null169 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
adler32null188 function adler32; external;
adler32_combinenull189 function adler32_combine; external;
compressnull190 function compress; external;
compress2null191 function compress2; external;
compressBoundnull192 function compressBound; external;
crc32null193 function crc32; external;
crc32_combinenull194 function crc32_combine; external;
deflatenull195 function deflate; external;
deflateBoundnull196 function deflateBound; external;
deflateCopynull197 function deflateCopy; external;
deflateEndnull198 function deflateEnd; external;
deflateInit_null199 function deflateInit_; external;
deflateInit2_null200 function deflateInit2_; external;
deflateParamsnull201 function deflateParams; external;
deflatePendingnull202 function deflatePending; external;
deflatePrimenull203 function deflatePrime; external;
deflateResetnull204 function deflateReset; external;
deflateSetDictionarynull205 function deflateSetDictionary; external;
deflateSetHeadernull206 function deflateSetHeader; external;
deflateTunenull207 function deflateTune; external;
inflatenull208 function inflate; external;
inflateBacknull209 function inflateBack; external;
inflateBackEndnull210 function inflateBackEnd; external;
inflateBackInit_null211 function inflateBackInit_; external;
inflateCopynull212 function inflateCopy; external;
inflateEndnull213 function inflateEnd; external;
inflateGetHeadernull214 function inflateGetHeader; external;
inflateInit_null215 function inflateInit_; external;
inflateInit2_null216 function inflateInit2_; external;
inflateMarknull217 function inflateMark; external;
inflatePrimenull218 function inflatePrime; external;
inflateResetnull219 function inflateReset; external;
inflateReset2null220 function inflateReset2; external;
inflateSetDictionarynull221 function inflateSetDictionary; external;
inflateSyncnull222 function inflateSync; external;
uncompressnull223 function uncompress; external;
zlibCompileFlagsnull224 function zlibCompileFlags; external;
zlibVersionnull225 function zlibVersion; external;
226
deflateInitnull227 function deflateInit(var strm: z_stream; level: Integer): Integer;
228 begin
229 Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream));
230 end;
231
deflateInit2null232 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
inflateInitnull239 function inflateInit(var strm: z_stream): Integer;
240 begin
241 Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream));
242 end;
243
inflateInit2null244 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
245 begin
246 Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream));
247 end;
248
inflateBackInitnull249 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
_mallocnull256 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.
277