zlibpas.pas 7.8 KB

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