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.3';
14
15 type
paque()16 alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
17 cdecl;
18 free_func = procedure(opaque, address: Pointer);
19 cdecl;
20
paque()21 in_func = function(opaque: Pointer; var buf: PByte): Integer;
22 cdecl;
paque()23 out_func = function(opaque: Pointer; buf: PByte; size: Integer): Integer;
24 cdecl;
25
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 *)
31
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 *)
35
36 msg: PChar; (* last error message, NULL if no error *)
37 state: Pointer; (* not visible by applications *)
38
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 *)
42
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 *)
46 end;
47
48 (* constants *)
49 const
50 Z_NO_FLUSH = 0;
51 Z_PARTIAL_FLUSH = 1;
52 Z_SYNC_FLUSH = 2;
53 Z_FULL_FLUSH = 3;
54 Z_FINISH = 4;
55
56 Z_OK = 0;
57 Z_STREAM_END = 1;
58 Z_NEED_DICT = 2;
59 Z_ERRNO = -1;
60 Z_STREAM_ERROR = -2;
61 Z_DATA_ERROR = -3;
62 Z_MEM_ERROR = -4;
63 Z_BUF_ERROR = -5;
64 Z_VERSION_ERROR = -6;
65
66 Z_NO_COMPRESSION = 0;
67 Z_BEST_SPEED = 1;
68 Z_BEST_COMPRESSION = 9;
69 Z_DEFAULT_COMPRESSION = -1;
70
71 Z_FILTERED = 1;
72 Z_HUFFMAN_ONLY = 2;
73 Z_RLE = 3;
74 Z_DEFAULT_STRATEGY = 0;
75
76 Z_BINARY = 0;
77 Z_ASCII = 1;
78 Z_UNKNOWN = 2;
79
80 Z_DEFLATED = 8;
81
82 (* basic functions *)
zlibVersion()83 function zlibVersion: PChar;
deflateInit(var strm: z_stream; level: Integer)84 function deflateInit(var strm: z_stream; level: Integer): Integer;
deflate(var strm: z_stream; flush: Integer)85 function deflate(var strm: z_stream; flush: Integer): Integer;
deflateEnd(var strm: z_stream)86 function deflateEnd(var strm: z_stream): Integer;
inflateInit(var strm: z_stream)87 function inflateInit(var strm: z_stream): Integer;
inflate(var strm: z_stream; flush: Integer)88 function inflate(var strm: z_stream; flush: Integer): Integer;
inflateEnd(var strm: z_stream)89 function inflateEnd(var strm: z_stream): Integer;
90
91 (* advanced functions *)
deflateInit2(var strm: z_stream; level, method, windowBits,92 function deflateInit2(var strm: z_stream; level, method, windowBits,
93 memLevel, strategy: Integer): Integer;
deflateSetDictionary(var strm: z_stream; const dictionary: PChar;94 function deflateSetDictionary(var strm: z_stream; const dictionary: PChar;
95 dictLength: Integer): Integer;
deflateCopy(var dest, source: z_stream)96 function deflateCopy(var dest, source: z_stream): Integer;
deflateReset(var strm: z_stream)97 function deflateReset(var strm: z_stream): Integer;
deflateParams(var strm: z_stream; level, strategy: Integer)98 function deflateParams(var strm: z_stream; level, strategy: Integer): Integer;
deflateBound(var strm: z_stream; sourceLen: LongInt)99 function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt;
deflatePrime(var strm: z_stream; bits, value: Integer)100 function deflatePrime(var strm: z_stream; bits, value: Integer): Integer;
inflateInit2(var strm: z_stream; windowBits: Integer)101 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
inflateSetDictionary(var strm: z_stream; const dictionary: PChar;102 function inflateSetDictionary(var strm: z_stream; const dictionary: PChar;
103 dictLength: Integer): Integer;
inflateSync(var strm: z_stream)104 function inflateSync(var strm: z_stream): Integer;
inflateCopy(var dest, source: z_stream)105 function inflateCopy(var dest, source: z_stream): Integer;
inflateReset(var strm: z_stream)106 function inflateReset(var strm: z_stream): Integer;
inflateBackInit(var strm: z_stream;107 function inflateBackInit(var strm: z_stream;
108 windowBits: Integer; window: PChar): Integer;
inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer;109 function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer;
110 out_fn: out_func; out_desc: Pointer): Integer;
inflateBackEnd(var strm: z_stream)111 function inflateBackEnd(var strm: z_stream): Integer;
zlibCompileFlags()112 function zlibCompileFlags: LongInt;
113
114 (* utility functions *)
compress(dest: PChar; var destLen: LongInt;115 function compress(dest: PChar; var destLen: LongInt;
116 const source: PChar; sourceLen: LongInt): Integer;
compress2(dest: PChar; var destLen: LongInt;117 function compress2(dest: PChar; var destLen: LongInt;
118 const source: PChar; sourceLen: LongInt;
119 level: Integer): Integer;
compressBound(sourceLen: LongInt)120 function compressBound(sourceLen: LongInt): LongInt;
uncompress(dest: PChar; var destLen: LongInt;121 function uncompress(dest: PChar; var destLen: LongInt;
122 const source: PChar; sourceLen: LongInt): Integer;
123
124 (* checksum functions *)
adler32(adler: LongInt; const buf: PChar; len: Integer)125 function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt;
crc32(crc: LongInt; const buf: PChar; len: Integer)126 function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt;
127
128 (* various hacks, don't look :) *)
deflateInit_(var strm: z_stream; level: Integer;129 function deflateInit_(var strm: z_stream; level: Integer;
130 const version: PChar; stream_size: Integer): Integer;
inflateInit_(var strm: z_stream; const version: PChar;131 function inflateInit_(var strm: z_stream; const version: PChar;
132 stream_size: Integer): Integer;
deflateInit2_(var strm: z_stream;133 function deflateInit2_(var strm: z_stream;
134 level, method, windowBits, memLevel, strategy: Integer;
135 const version: PChar; stream_size: Integer): Integer;
inflateInit2_(var strm: z_stream; windowBits: Integer;136 function inflateInit2_(var strm: z_stream; windowBits: Integer;
137 const version: PChar; stream_size: Integer): Integer;
inflateBackInit_(var strm: z_stream;138 function inflateBackInit_(var strm: z_stream;
139 windowBits: Integer; window: PChar;
140 const version: PChar; stream_size: Integer): Integer;
141
142
143 implementation
144
145 {$L adler32.obj}
146 {$L compress.obj}
147 {$L crc32.obj}
148 {$L deflate.obj}
149 {$L infback.obj}
150 {$L inffast.obj}
151 {$L inflate.obj}
152 {$L inftrees.obj}
153 {$L trees.obj}
154 {$L uncompr.obj}
155 {$L zutil.obj}
156
adler32()157 function adler32; external;
compress()158 function compress; external;
compress2()159 function compress2; external;
compressBound()160 function compressBound; external;
crc32()161 function crc32; external;
deflate()162 function deflate; external;
deflateBound()163 function deflateBound; external;
deflateCopy()164 function deflateCopy; external;
deflateEnd()165 function deflateEnd; external;
deflateInit_()166 function deflateInit_; external;
deflateInit2_()167 function deflateInit2_; external;
deflateParams()168 function deflateParams; external;
deflatePrime()169 function deflatePrime; external;
deflateReset()170 function deflateReset; external;
deflateSetDictionary()171 function deflateSetDictionary; external;
inflate()172 function inflate; external;
inflateBack()173 function inflateBack; external;
inflateBackEnd()174 function inflateBackEnd; external;
inflateBackInit_()175 function inflateBackInit_; external;
inflateCopy()176 function inflateCopy; external;
inflateEnd()177 function inflateEnd; external;
inflateInit_()178 function inflateInit_; external;
inflateInit2_()179 function inflateInit2_; external;
inflateReset()180 function inflateReset; external;
inflateSetDictionary()181 function inflateSetDictionary; external;
inflateSync()182 function inflateSync; external;
uncompress()183 function uncompress; external;
zlibCompileFlags()184 function zlibCompileFlags; external;
zlibVersion()185 function zlibVersion; external;
186
deflateInit(var strm: z_stream; level: Integer)187 function deflateInit(var strm: z_stream; level: Integer): Integer;
188 begin
189 Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream));
190 end;
191
deflateInit2(var strm: z_stream; level, method, windowBits, memLevel,192 function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel,
193 strategy: Integer): Integer;
194 begin
195 Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
196 ZLIB_VERSION, sizeof(z_stream));
197 end;
198
inflateInit(var strm: z_stream)199 function inflateInit(var strm: z_stream): Integer;
200 begin
201 Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream));
202 end;
203
inflateInit2(var strm: z_stream; windowBits: Integer)204 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
205 begin
206 Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream));
207 end;
208
inflateBackInit(var strm: z_stream;209 function inflateBackInit(var strm: z_stream;
210 windowBits: Integer; window: PChar): Integer;
211 begin
212 Result := inflateBackInit_(strm, windowBits, window,
213 ZLIB_VERSION, sizeof(z_stream));
214 end;
215
_malloc(Size: Integer)216 function _malloc(Size: Integer): Pointer; cdecl;
217 begin
218 GetMem(Result, Size);
219 end;
220
221 procedure _free(Block: Pointer); cdecl;
222 begin
223 FreeMem(Block);
224 end;
225
226 procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl;
227 begin
228 FillChar(P^, count, B);
229 end;
230
231 procedure _memcpy(dest, source: Pointer; count: Integer); cdecl;
232 begin
233 Move(source^, dest^, count);
234 end;
235
236 end.
237