• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.8';
14   ZLIB_VERNUM  = $1280;
15 
16 type
paque()17   alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
18                  cdecl;
19   free_func  = procedure(opaque, address: Pointer);
20                  cdecl;
21 
paque()22   in_func    = function(opaque: Pointer; var buf: PByte): Integer;
23                  cdecl;
paque()24   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 *)
zlibVersion()105 function zlibVersion: PChar;
deflateInit(var strm: z_stream; level: Integer)106 function deflateInit(var strm: z_stream; level: Integer): Integer;
deflate(var strm: z_stream; flush: Integer)107 function deflate(var strm: z_stream; flush: Integer): Integer;
deflateEnd(var strm: z_stream)108 function deflateEnd(var strm: z_stream): Integer;
inflateInit(var strm: z_stream)109 function inflateInit(var strm: z_stream): Integer;
inflate(var strm: z_stream; flush: Integer)110 function inflate(var strm: z_stream; flush: Integer): Integer;
inflateEnd(var strm: z_stream)111 function inflateEnd(var strm: z_stream): Integer;
112 
113 (* advanced functions *)
deflateInit2(var strm: z_stream; level, method, windowBits,114 function deflateInit2(var strm: z_stream; level, method, windowBits,
115                       memLevel, strategy: Integer): Integer;
deflateSetDictionary(var strm: z_stream; const dictionary: PChar;116 function deflateSetDictionary(var strm: z_stream; const dictionary: PChar;
117                               dictLength: Integer): Integer;
deflateCopy(var dest, source: z_stream)118 function deflateCopy(var dest, source: z_stream): Integer;
deflateReset(var strm: z_stream)119 function deflateReset(var strm: z_stream): Integer;
deflateParams(var strm: z_stream; level, strategy: Integer)120 function deflateParams(var strm: z_stream; level, strategy: Integer): Integer;
deflateTune(var strm: z_stream; good_length, max_lazy, nice_length, max_chain: Integer)121 function deflateTune(var strm: z_stream; good_length, max_lazy, nice_length, max_chain: Integer): Integer;
deflateBound(var strm: z_stream; sourceLen: LongInt)122 function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt;
deflatePending(var strm: z_stream; var pending: Integer; var bits: Integer)123 function deflatePending(var strm: z_stream; var pending: Integer; var bits: Integer): Integer;
deflatePrime(var strm: z_stream; bits, value: Integer)124 function deflatePrime(var strm: z_stream; bits, value: Integer): Integer;
deflateSetHeader(var strm: z_stream; head: gz_header)125 function deflateSetHeader(var strm: z_stream; head: gz_header): Integer;
inflateInit2(var strm: z_stream; windowBits: Integer)126 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
inflateSetDictionary(var strm: z_stream; const dictionary: PChar;127 function inflateSetDictionary(var strm: z_stream; const dictionary: PChar;
128                               dictLength: Integer): Integer;
inflateSync(var strm: z_stream)129 function inflateSync(var strm: z_stream): Integer;
inflateCopy(var dest, source: z_stream)130 function inflateCopy(var dest, source: z_stream): Integer;
inflateReset(var strm: z_stream)131 function inflateReset(var strm: z_stream): Integer;
inflateReset2(var strm: z_stream; windowBits: Integer)132 function inflateReset2(var strm: z_stream; windowBits: Integer): Integer;
inflatePrime(var strm: z_stream; bits, value: Integer)133 function inflatePrime(var strm: z_stream; bits, value: Integer): Integer;
inflateMark(var strm: z_stream)134 function inflateMark(var strm: z_stream): LongInt;
inflateGetHeader(var strm: z_stream; var head: gz_header)135 function inflateGetHeader(var strm: z_stream; var head: gz_header): Integer;
inflateBackInit(var strm: z_stream;136 function inflateBackInit(var strm: z_stream;
137                          windowBits: Integer; window: PChar): Integer;
inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer;138 function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer;
139                      out_fn: out_func; out_desc: Pointer): Integer;
inflateBackEnd(var strm: z_stream)140 function inflateBackEnd(var strm: z_stream): Integer;
zlibCompileFlags()141 function zlibCompileFlags: LongInt;
142 
143 (* utility functions *)
compress(dest: PChar; var destLen: LongInt;144 function compress(dest: PChar; var destLen: LongInt;
145                   const source: PChar; sourceLen: LongInt): Integer;
compress2(dest: PChar; var destLen: LongInt;146 function compress2(dest: PChar; var destLen: LongInt;
147                   const source: PChar; sourceLen: LongInt;
148                   level: Integer): Integer;
compressBound(sourceLen: LongInt)149 function compressBound(sourceLen: LongInt): LongInt;
uncompress(dest: PChar; var destLen: LongInt;150 function uncompress(dest: PChar; var destLen: LongInt;
151                     const source: PChar; sourceLen: LongInt): Integer;
152 
153 (* checksum functions *)
adler32(adler: LongInt; const buf: PChar; len: Integer)154 function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt;
adler32_combine(adler1, adler2, len2: LongInt)155 function adler32_combine(adler1, adler2, len2: LongInt): LongInt;
crc32(crc: LongInt; const buf: PChar; len: Integer)156 function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt;
crc32_combine(crc1, crc2, len2: LongInt)157 function crc32_combine(crc1, crc2, len2: LongInt): LongInt;
158 
159 (* various hacks, don't look :) *)
deflateInit_(var strm: z_stream; level: Integer;160 function deflateInit_(var strm: z_stream; level: Integer;
161                       const version: PChar; stream_size: Integer): Integer;
inflateInit_(var strm: z_stream; const version: PChar;162 function inflateInit_(var strm: z_stream; const version: PChar;
163                       stream_size: Integer): Integer;
deflateInit2_(var strm: z_stream;164 function deflateInit2_(var strm: z_stream;
165                        level, method, windowBits, memLevel, strategy: Integer;
166                        const version: PChar; stream_size: Integer): Integer;
inflateInit2_(var strm: z_stream; windowBits: Integer;167 function inflateInit2_(var strm: z_stream; windowBits: Integer;
168                        const version: PChar; stream_size: Integer): Integer;
inflateBackInit_(var strm: z_stream;169 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 
adler32()188 function adler32; external;
adler32_combine()189 function adler32_combine; external;
compress()190 function compress; external;
compress2()191 function compress2; external;
compressBound()192 function compressBound; external;
crc32()193 function crc32; external;
crc32_combine()194 function crc32_combine; external;
deflate()195 function deflate; external;
deflateBound()196 function deflateBound; external;
deflateCopy()197 function deflateCopy; external;
deflateEnd()198 function deflateEnd; external;
deflateInit_()199 function deflateInit_; external;
deflateInit2_()200 function deflateInit2_; external;
deflateParams()201 function deflateParams; external;
deflatePending()202 function deflatePending; external;
deflatePrime()203 function deflatePrime; external;
deflateReset()204 function deflateReset; external;
deflateSetDictionary()205 function deflateSetDictionary; external;
deflateSetHeader()206 function deflateSetHeader; external;
deflateTune()207 function deflateTune; external;
inflate()208 function inflate; external;
inflateBack()209 function inflateBack; external;
inflateBackEnd()210 function inflateBackEnd; external;
inflateBackInit_()211 function inflateBackInit_; external;
inflateCopy()212 function inflateCopy; external;
inflateEnd()213 function inflateEnd; external;
inflateGetHeader()214 function inflateGetHeader; external;
inflateInit_()215 function inflateInit_; external;
inflateInit2_()216 function inflateInit2_; external;
inflateMark()217 function inflateMark; external;
inflatePrime()218 function inflatePrime; external;
inflateReset()219 function inflateReset; external;
inflateReset2()220 function inflateReset2; external;
inflateSetDictionary()221 function inflateSetDictionary; external;
inflateSync()222 function inflateSync; external;
uncompress()223 function uncompress; external;
zlibCompileFlags()224 function zlibCompileFlags; external;
zlibVersion()225 function zlibVersion; external;
226 
deflateInit(var strm: z_stream; level: Integer)227 function deflateInit(var strm: z_stream; level: Integer): Integer;
228 begin
229   Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream));
230 end;
231 
deflateInit2(var strm: z_stream; level, method, windowBits, memLevel,232 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 
inflateInit(var strm: z_stream)239 function inflateInit(var strm: z_stream): Integer;
240 begin
241   Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream));
242 end;
243 
inflateInit2(var strm: z_stream; windowBits: Integer)244 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
245 begin
246   Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream));
247 end;
248 
inflateBackInit(var strm: z_stream;249 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 
_malloc(Size: Integer)256 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