source: Vago/zlib-1.2.8/contrib/pascal/zlibpas.pas@ 1049

Last change on this file since 1049 was 1049, checked in by s10k, 8 years ago
File size: 9.9 KB
Line 
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
8unit zlibpas;
9
10interface
11
12const
13 ZLIB_VERSION = '1.2.8';
14 ZLIB_VERNUM = $1280;
15
16type
17 alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
18 cdecl;
19 free_func = procedure(opaque, address: Pointer);
20 cdecl;
21
22 in_func = function(opaque: Pointer; var buf: PByte): Integer;
23 cdecl;
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 *)
67const
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 *)
105function zlibVersion: PChar;
106function deflateInit(var strm: z_stream; level: Integer): Integer;
107function deflate(var strm: z_stream; flush: Integer): Integer;
108function deflateEnd(var strm: z_stream): Integer;
109function inflateInit(var strm: z_stream): Integer;
110function inflate(var strm: z_stream; flush: Integer): Integer;
111function inflateEnd(var strm: z_stream): Integer;
112
113(* advanced functions *)
114function deflateInit2(var strm: z_stream; level, method, windowBits,
115 memLevel, strategy: Integer): Integer;
116function deflateSetDictionary(var strm: z_stream; const dictionary: PChar;
117 dictLength: Integer): Integer;
118function deflateCopy(var dest, source: z_stream): Integer;
119function deflateReset(var strm: z_stream): Integer;
120function deflateParams(var strm: z_stream; level, strategy: Integer): Integer;
121function deflateTune(var strm: z_stream; good_length, max_lazy, nice_length, max_chain: Integer): Integer;
122function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt;
123function deflatePending(var strm: z_stream; var pending: Integer; var bits: Integer): Integer;
124function deflatePrime(var strm: z_stream; bits, value: Integer): Integer;
125function deflateSetHeader(var strm: z_stream; head: gz_header): Integer;
126function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
127function inflateSetDictionary(var strm: z_stream; const dictionary: PChar;
128 dictLength: Integer): Integer;
129function inflateSync(var strm: z_stream): Integer;
130function inflateCopy(var dest, source: z_stream): Integer;
131function inflateReset(var strm: z_stream): Integer;
132function inflateReset2(var strm: z_stream; windowBits: Integer): Integer;
133function inflatePrime(var strm: z_stream; bits, value: Integer): Integer;
134function inflateMark(var strm: z_stream): LongInt;
135function inflateGetHeader(var strm: z_stream; var head: gz_header): Integer;
136function inflateBackInit(var strm: z_stream;
137 windowBits: Integer; window: PChar): Integer;
138function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer;
139 out_fn: out_func; out_desc: Pointer): Integer;
140function inflateBackEnd(var strm: z_stream): Integer;
141function zlibCompileFlags: LongInt;
142
143(* utility functions *)
144function compress(dest: PChar; var destLen: LongInt;
145 const source: PChar; sourceLen: LongInt): Integer;
146function compress2(dest: PChar; var destLen: LongInt;
147 const source: PChar; sourceLen: LongInt;
148 level: Integer): Integer;
149function compressBound(sourceLen: LongInt): LongInt;
150function uncompress(dest: PChar; var destLen: LongInt;
151 const source: PChar; sourceLen: LongInt): Integer;
152
153(* checksum functions *)
154function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt;
155function adler32_combine(adler1, adler2, len2: LongInt): LongInt;
156function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt;
157function crc32_combine(crc1, crc2, len2: LongInt): LongInt;
158
159(* various hacks, don't look :) *)
160function deflateInit_(var strm: z_stream; level: Integer;
161 const version: PChar; stream_size: Integer): Integer;
162function inflateInit_(var strm: z_stream; const version: PChar;
163 stream_size: Integer): Integer;
164function deflateInit2_(var strm: z_stream;
165 level, method, windowBits, memLevel, strategy: Integer;
166 const version: PChar; stream_size: Integer): Integer;
167function inflateInit2_(var strm: z_stream; windowBits: Integer;
168 const version: PChar; stream_size: Integer): Integer;
169function inflateBackInit_(var strm: z_stream;
170 windowBits: Integer; window: PChar;
171 const version: PChar; stream_size: Integer): Integer;
172
173
174implementation
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
188function adler32; external;
189function adler32_combine; external;
190function compress; external;
191function compress2; external;
192function compressBound; external;
193function crc32; external;
194function crc32_combine; external;
195function deflate; external;
196function deflateBound; external;
197function deflateCopy; external;
198function deflateEnd; external;
199function deflateInit_; external;
200function deflateInit2_; external;
201function deflateParams; external;
202function deflatePending; external;
203function deflatePrime; external;
204function deflateReset; external;
205function deflateSetDictionary; external;
206function deflateSetHeader; external;
207function deflateTune; external;
208function inflate; external;
209function inflateBack; external;
210function inflateBackEnd; external;
211function inflateBackInit_; external;
212function inflateCopy; external;
213function inflateEnd; external;
214function inflateGetHeader; external;
215function inflateInit_; external;
216function inflateInit2_; external;
217function inflateMark; external;
218function inflatePrime; external;
219function inflateReset; external;
220function inflateReset2; external;
221function inflateSetDictionary; external;
222function inflateSync; external;
223function uncompress; external;
224function zlibCompileFlags; external;
225function zlibVersion; external;
226
227function deflateInit(var strm: z_stream; level: Integer): Integer;
228begin
229 Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream));
230end;
231
232function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel,
233 strategy: Integer): Integer;
234begin
235 Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
236 ZLIB_VERSION, sizeof(z_stream));
237end;
238
239function inflateInit(var strm: z_stream): Integer;
240begin
241 Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream));
242end;
243
244function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
245begin
246 Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream));
247end;
248
249function inflateBackInit(var strm: z_stream;
250 windowBits: Integer; window: PChar): Integer;
251begin
252 Result := inflateBackInit_(strm, windowBits, window,
253 ZLIB_VERSION, sizeof(z_stream));
254end;
255
256function _malloc(Size: Integer): Pointer; cdecl;
257begin
258 GetMem(Result, Size);
259end;
260
261procedure _free(Block: Pointer); cdecl;
262begin
263 FreeMem(Block);
264end;
265
266procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl;
267begin
268 FillChar(P^, count, B);
269end;
270
271procedure _memcpy(dest, source: Pointer; count: Integer); cdecl;
272begin
273 Move(source^, dest^, count);
274end;
275
276end.
Note: See TracBrowser for help on using the repository browser.