zlibpas.pas 9.9 KB

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