-
Notifications
You must be signed in to change notification settings - Fork 10
/
ZMZLibExApi.pas
362 lines (277 loc) · 13.6 KB
/
ZMZLibExApi.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
unit ZMZLibExApi;
{*************************************************************************************************
* ZLibExApi.pas *
* *
* copyright (c) 2000-2012 base2 technologies *
* copyright (c) 1995-2002 Borland Software Corporation *
* *
* revision history *
* 2013.05.23 updated to zlib version 1.2.8 *
* 2012.05.21 updated for win64 (delphi xe2) *
* moved win32 obj files to win32 subfolder *
* changed win32 obj options to exclude the underscore *
* 2012.05.07 updated to zlib version 1.2.7 *
* 2012.03.05 udpated to zlib version 1.2.6 *
* 2010.04.20 updated to zlib version 1.2.5 *
* 2010.04.15 updated to zlib version 1.2.4 *
* 2005.07.25 updated to zlib version 1.2.3 *
* 2005.01.11 updated to zlib version 1.2.2 *
* 2004.01.06 updated to zlib version 1.2.1 *
* 2002.03.15 updated to zlib version 1.1.4 *
* *
* acknowledgments *
* burak kalayci *
* 2002.03.15 informing me about the zlib 1.1.4 update *
* 2004.01.06 informing me about the zlib 1.2.1 update *
* *
* vicente sanchez-alarcos *
* 2005.01.11 informing me about the zlib 1.2.2 update *
* *
* mathijs van veluw *
* 2005.07.25 informing me about the zlib 1.2.3 update *
* *
* tommi prami *
* 2012.03.05 informing me about the zlib 1.2.6 update *
* *
* marian pascalau *
* 2012.05.21 providing the win64 obj files and your win64 modifications *
* *
* roman ganz *
* 2013.05.23 informing me about the zlib 1.2.8 update *
*************************************************************************************************}
(* Adapted for ZipMaster 1.9.2 Russell Peters *)
// modified 2013-04-27
interface
{$I ZipVers.inc}
{$IFDEF VERpre6}
uses windows;
{$endif}
const
{** version ids *******************************************************************************}
ZLIB_VERSION: PAnsiChar = '1.2.8';
ZLIB_VERNUM = $1280;
ZLIB_VER_MAJOR = 1;
ZLIB_VER_MINOR = 2;
ZLIB_VER_REVISION = 8;
ZLIB_VER_SUBREVISION = 0;
{** compression methods ***********************************************************************}
Z_DEFLATED = 8;
{** information flags *************************************************************************}
Z_INFO_FLAG_SIZE = $1;
Z_INFO_FLAG_CRC = $2;
Z_INFO_FLAG_ADLER = $4;
Z_INFO_NONE = 0;
Z_INFO_DEFAULT = Z_INFO_FLAG_SIZE or Z_INFO_FLAG_CRC;
{** flush constants ***************************************************************************}
Z_NO_FLUSH = 0;
Z_PARTIAL_FLUSH = 1;
Z_SYNC_FLUSH = 2;
Z_FULL_FLUSH = 3;
Z_FINISH = 4;
Z_BLOCK = 5;
Z_TREES = 6;
{** return codes ******************************************************************************}
Z_OK = 0;
Z_STREAM_END = 1;
Z_NEED_DICT = 2;
Z_ERRNO = (-1);
Z_STREAM_ERROR = (-2);
Z_DATA_ERROR = (-3);
Z_MEM_ERROR = (-4);
Z_BUF_ERROR = (-5);
Z_VERSION_ERROR = (-6);
{** compression levels ************************************************************************}
Z_NO_COMPRESSION = 0;
Z_BEST_SPEED = 1;
Z_BEST_COMPRESSION = 9;
Z_DEFAULT_COMPRESSION = (-1);
{** compression strategies ********************************************************************}
Z_FILTERED = 1;
Z_HUFFMAN_ONLY = 2;
Z_RLE = 3;
Z_FIXED = 4;
Z_DEFAULT_STRATEGY = 0;
{** data types ********************************************************************************}
Z_BINARY = 0;
Z_TEXT = 1;
Z_ASCII = Z_TEXT;
Z_UNKNOWN = 2;
{** return code messages **********************************************************************}
z_errmsg: Array [0..9] of String = (
'Need dictionary', // Z_NEED_DICT (2)
'Stream end', // Z_STREAM_END (1)
'OK', // Z_OK (0)
'File error', // Z_ERRNO (-1)
'Stream error', // Z_STREAM_ERROR (-2)
'Data error', // Z_DATA_ERROR (-3)
'Insufficient memory', // Z_MEM_ERROR (-4)
'Buffer error', // Z_BUF_ERROR (-5)
'Incompatible version', // Z_VERSION_ERROR (-6)
''
);
type
TZAlloc = function (opaque: Pointer; items, size: Integer): Pointer; cdecl;
TZFree = procedure (opaque, block: Pointer); cdecl;
{** TZStreamRec *******************************************************************************}
TZStreamRec = packed record
next_in : PByte; // next input byte
avail_in : Cardinal; // number of bytes available at next_in
total_in : Longword; // total nb of input bytes read so far
next_out : PByte; // next output byte should be put here
avail_out: Cardinal; // remaining free space at next_out
total_out: Longword; // total nb of bytes output so far
msg : PAnsiChar; // last error message, NULL if no error
state : Pointer; // not visible by applications
zalloc : TZAlloc; // used to allocate the internal state
zfree : TZFree; // used to free the internal state
opaque : Pointer; // private data object passed to zalloc and zfree
data_type: Integer; // best guess about the data type: ascii or binary
adler : Longword; // adler32 value of the uncompressed data
reserved : Longword; // reserved for future use
end;
{** macros **************************************************************************************}
function deflateInit(var strm: TZStreamRec; level: Integer): Integer;
{$ifdef ZM_INLINE} inline; {$endif}
function deflateInit2(var strm: TZStreamRec; level, method, windowBits,
memLevel, strategy: Integer): Integer;
{$ifdef ZM_INLINE} inline; {$endif}
function inflateInit(var strm: TZStreamRec): Integer;
{$ifdef ZM_INLINE} inline; {$endif}
function inflateInit2(var strm: TZStreamRec; windowBits: Integer): Integer;
{$ifdef ZM_INLINE} inline; {$endif}
{** external routines ***************************************************************************}
function deflateInit_(var strm: TZStreamRec; level: Integer;
version: PAnsiChar; recsize: Integer): Integer;
function deflateInit2_(var strm: TZStreamRec; level, method, windowBits,
memLevel, strategy: Integer; version: PAnsiChar; recsize: Integer): Integer;
function deflate(var strm: TZStreamRec; flush: Integer): Integer;
function deflateEnd(var strm: TZStreamRec): Integer;
function deflateReset(var strm: TZStreamRec): Integer;
function inflateInit_(var strm: TZStreamRec; version: PAnsiChar;
recsize: Integer): Integer;
function inflateInit2_(var strm: TZStreamRec; windowBits: Integer;
version: PAnsiChar; recsize: Integer): Integer;
function inflate(var strm: TZStreamRec; flush: Integer): Integer;
function inflateEnd(var strm: TZStreamRec): Integer;
function inflateReset(var strm: TZStreamRec): Integer;
function adler32(adler: Longint; const buf; len: Integer): Longint;
//function crc32(crc: Longint; const buf; len: Integer): Longint;
//function get_crc_table: pointer;
implementation
{*************************************************************************************************
* link zlib code *
* *
* bcc32 flags *
* -c -O2 -Ve -X -pr -a8 -b -d -k- -vi -tWM -u- *
* *
* note: do not reorder the following -- doing so will result in external *
* functions being undefined *
*************************************************************************************************}
{$ifdef WIN64}
{$L zlib\win64\deflate.obj}
{$L zlib\win64\inflate.obj}
{$L zlib\win64\inftrees.obj}
{$L zlib\win64\infback.obj}
{$L zlib\win64\inffast.obj}
{$L zlib\win64\trees.obj}
{$L zlib\win64\compress.obj}
{$L zlib\win64\adler32.obj}
//{$L zlib\win64\crc32.obj}
{$else}
{$L zlib\win32\deflate.obj}
{$L zlib\win32\inflate.obj}
{$L zlib\win32\inftrees.obj}
{$L zlib\win32\infback.obj}
{$L zlib\win32\inffast.obj}
{$L zlib\win32\trees.obj}
{$L zlib\win32\compress.obj}
{$L zlib\win32\adler32.obj}
//{$L zlib\win32\crc32.obj}
{$endif}
{** macros **************************************************************************************}
function deflateInit(var strm: TZStreamRec; level: Integer): Integer;
begin
result := deflateInit_(strm, level, ZLIB_VERSION, SizeOf(TZStreamRec));
end;
function deflateInit2(var strm: TZStreamRec; level, method, windowBits,
memLevel, strategy: Integer): Integer;
begin
result := deflateInit2_(strm, level, method, windowBits,
memLevel, strategy, ZLIB_VERSION, SizeOf(TZStreamRec));
end;
function inflateInit(var strm: TZStreamRec): Integer;
begin
result := inflateInit_(strm, ZLIB_VERSION, SizeOf(TZStreamRec));
end;
function inflateInit2(var strm: TZStreamRec; windowBits: Integer): Integer;
begin
result := inflateInit2_(strm, windowBits, ZLIB_VERSION,
SizeOf(TZStreamRec));
end;
{** external routines ***************************************************************************}
function deflateInit_(var strm: TZStreamRec; level: Integer;
version: PAnsiChar; recsize: Integer): Integer;
external;
function deflateInit2_(var strm: TZStreamRec; level, method, windowBits,
memLevel, strategy: Integer; version: PAnsiChar; recsize: Integer): Integer;
external;
function deflate(var strm: TZStreamRec; flush: Integer): Integer;
external;
function deflateEnd(var strm: TZStreamRec): Integer;
external;
function deflateReset(var strm: TZStreamRec): Integer;
external;
function inflateInit_(var strm: TZStreamRec; version: PAnsiChar;
recsize: Integer): Integer;
external;
function inflateInit2_(var strm: TZStreamRec; windowBits: Integer;
version: PAnsiChar; recsize: Integer): Integer;
external;
function inflate(var strm: TZStreamRec; flush: Integer): Integer;
external;
function inflateEnd(var strm: TZStreamRec): Integer;
external;
function inflateReset(var strm: TZStreamRec): Integer;
external;
function adler32(adler: Longint; const buf; len: Integer): Longint;
external;
//function crc32(crc: Longint; const buf; len: Integer): Longint;
// external;
//function get_crc_table: pointer; external;
{** zlib function implementations ***************************************************************}
function zcalloc(opaque: Pointer; items, size: Integer): Pointer;
begin
GetMem(result,items * size);
end;
procedure zcfree(opaque, block: Pointer);
begin
FreeMem(block);
end;
{** c function implementations ******************************************************************}
function memset(p: Pointer; b: Byte; count: Integer): Pointer; cdecl;
begin
FillChar(p^, count, b);
result := p;
end;
procedure memcpy(dest, source: Pointer; count: Integer); cdecl;
begin
Move(source^, dest^, count);
end;
//{$ifdef WIN64}
function zmemzero(p: Pointer; count: Integer): Pointer; cdecl;
begin
FillChar(p^, count, 0);
result := p;
end;
procedure zmemcpy(dest, source: Pointer; count: Integer); cdecl;
begin
Move(source^, dest^, count);
end;
//{$endif}
{$ifndef WIN64}
procedure _llmod;
asm
jmp System.@_llmod;
end;
{$endif}
end.