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