zlib.pp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. {$ifndef NO_SMART_LINK}
  2. {$smartlink on}
  3. {$endif}
  4. unit zlib;
  5. interface
  6. { Needed for array of const }
  7. {$mode objfpc}
  8. { for linux for linking with libc }
  9. {$ifdef unix}
  10. {$linklib c}
  11. {$endif}
  12. {$PACKRECORDS 4}
  13. uses
  14. ctypes;
  15. const
  16. ZLIB_VERSION = '1.1.3';
  17. {$ifdef netware} {zlib.nlm comes with netware6}
  18. libz='zlib';
  19. {$else}
  20. {$ifdef windows}
  21. libz='zlib1';
  22. {$else windows}
  23. libz='z';
  24. {$endif windows}
  25. {$endif}
  26. type
  27. { Compatible with paszlib }
  28. Uint = Longint;
  29. Ulong = Longint;
  30. Ulongf = Longint;
  31. Pulongf = ^Ulongf;
  32. z_off_t = longint;
  33. pbyte = ^byte;
  34. pbytef = ^byte;
  35. TAllocfunc = function (opaque:pointer; items:uInt; size:uInt):pointer;cdecl;
  36. TFreeFunc = procedure (opaque:pointer; address:pointer);cdecl;
  37. TInternalState = record
  38. end;
  39. PInternalState = ^TInternalstate;
  40. TZStream = record
  41. next_in : pbytef;
  42. avail_in : uInt;
  43. total_in : uLong;
  44. next_out : pbytef;
  45. avail_out : uInt;
  46. total_out : uLong;
  47. msg : pbytef;
  48. state : PInternalState;
  49. zalloc : TAllocFunc;
  50. zfree : TFreeFunc;
  51. opaque : pointer;
  52. data_type : longint;
  53. adler : uLong;
  54. reserved : uLong;
  55. end;
  56. TZStreamRec = TZStream;
  57. PZstream = ^TZStream;
  58. gzFile = pointer;
  59. const
  60. Z_NO_FLUSH = 0;
  61. Z_PARTIAL_FLUSH = 1;
  62. Z_SYNC_FLUSH = 2;
  63. Z_FULL_FLUSH = 3;
  64. Z_FINISH = 4;
  65. Z_OK = 0;
  66. Z_STREAM_END = 1;
  67. Z_NEED_DICT = 2;
  68. Z_ERRNO = -(1);
  69. Z_STREAM_ERROR = -(2);
  70. Z_DATA_ERROR = -(3);
  71. Z_MEM_ERROR = -(4);
  72. Z_BUF_ERROR = -(5);
  73. Z_VERSION_ERROR = -(6);
  74. Z_NO_COMPRESSION = 0;
  75. Z_BEST_SPEED = 1;
  76. Z_BEST_COMPRESSION = 9;
  77. Z_DEFAULT_COMPRESSION = -(1);
  78. Z_FILTERED = 1;
  79. Z_HUFFMAN_ONLY = 2;
  80. Z_DEFAULT_STRATEGY = 0;
  81. Z_BINARY = 0;
  82. Z_ASCII = 1;
  83. Z_UNKNOWN = 2;
  84. Z_DEFLATED = 8;
  85. Z_NULL = 0;
  86. function zlibVersionpchar:pchar;cdecl;external libz name 'zlibVersion';
  87. function zlibVersion:string;
  88. function deflate(var strm:TZStream; flush:longint):longint;cdecl;external libz name 'deflate';
  89. function deflateEnd(var strm:TZStream):longint;cdecl;external libz name 'deflateEnd';
  90. function inflate(var strm:TZStream; flush:longint):longint;cdecl;external libz name 'inflate';
  91. function inflateEnd(var strm:TZStream):longint;cdecl;external libz name 'inflateEnd';
  92. function deflateSetDictionary(var strm:TZStream;dictionary : pbytef; dictLength:uInt):longint;cdecl;external libz name 'deflateSetDictionary';
  93. function deflateCopy(var dest,source:TZstream):longint;cdecl;external libz name 'deflateCopy';
  94. function deflateReset(var strm:TZStream):longint;cdecl;external libz name 'deflateReset';
  95. function deflateParams(var strm:TZStream; level:longint; strategy:longint):longint;cdecl;external libz name 'deflateParams';
  96. function inflateSetDictionary(var strm:TZStream;dictionary : pbytef; dictLength:uInt):longint;cdecl;external libz name 'inflateSetDictionary';
  97. function inflateSync(var strm:TZStream):longint;cdecl;external libz name 'inflateSync';
  98. function inflateReset(var strm:TZStream):longint;cdecl;external libz name 'inflateReset';
  99. function compress(dest:pbytef;destLen:puLongf; source : pbytef; sourceLen:uLong):cint;cdecl;external libz name 'compress';
  100. function compress2(dest:pbytef;destLen:puLongf; source : pbytef; sourceLen:uLong; level:cint):cint;cdecl;external libz name 'compress2';
  101. function uncompress(dest:pbytef;destLen:puLongf; source : pbytef; sourceLen:uLong):cint;cdecl;external libz name 'uncompress';
  102. function gzopen(path:pchar; mode:pchar):gzFile;cdecl;external libz name 'gzopen';
  103. function gzdopen(fd:longint; mode:pchar):gzFile;cdecl;external libz name 'gzdopen';
  104. function gzsetparams(thefile:gzFile; level:longint; strategy:longint):longint;cdecl;external libz name 'gzsetparams';
  105. function gzread(thefile:gzFile; buf:pointer; len:cardinal):longint;cdecl;external libz name 'gzread';
  106. function gzwrite(thefile:gzFile; buf:pointer; len:cardinal):longint;cdecl;external libz name 'gzwrite';
  107. function gzprintf(thefile:gzFile; format:pbytef; args:array of const):longint;cdecl;external libz name 'gzprintf';
  108. function gzputs(thefile:gzFile; s:pbytef):longint;cdecl;external libz name 'gzputs';
  109. function gzgets(thefile:gzFile; buf:pbytef; len:longint):pbytef;cdecl;external libz name 'gzgets';
  110. function gzputc(thefile:gzFile; c:char):char;cdecl;external libz name 'gzputc';
  111. function gzgetc(thefile:gzFile):char;cdecl;external libz name 'gzgetc';
  112. function gzflush(thefile:gzFile; flush:longint):longint;cdecl;external libz name 'gzflush';
  113. function gzseek(thefile:gzFile; offset:z_off_t; whence:longint):z_off_t;cdecl;external libz name 'gzseek';
  114. function gzrewind(thefile:gzFile):longint;cdecl;external libz name 'gzrewind';
  115. function gztell(thefile:gzFile):z_off_t;cdecl;external libz name 'gztell';
  116. function gzeof(thefile:gzFile):longbool;cdecl;external libz name 'gzeof';
  117. function gzclose(thefile:gzFile):longint;cdecl;external libz name 'gzclose';
  118. function gzerror(thefile:gzFile; var errnum:longint):pbytef;cdecl;external libz name 'gzerror';
  119. function adler32(adler:uLong;buf : pbytef; len:uInt):uLong;cdecl;external libz name 'adler32';
  120. function crc32(crc:uLong;buf : pbytef; len:uInt):uLong;cdecl;external libz name 'crc32';
  121. function deflateInit_(var strm:TZStream; level:longint; version:pchar; stream_size:longint):longint;cdecl;external libz name 'deflateInit_';
  122. function inflateInit_(var strm:TZStream; version:pchar; stream_size:longint):longint;cdecl;external libz name 'inflateInit_';
  123. function deflateInit(var strm:TZStream;level : longint) : longint;
  124. function inflateInit(var strm:TZStream) : longint;
  125. function deflateInit2_(var strm:TZStream; level:longint; method:longint; windowBits:longint; memLevel:longint;strategy:longint; version:pchar; stream_size:longint):longint;cdecl;external libz name 'deflateInit2_';
  126. function inflateInit2_(var strm:TZStream; windowBits:longint; version:pchar; stream_size:longint):longint;cdecl;external libz name 'inflateInit2_';
  127. function deflateInit2(var strm:TZStream;level,method,windowBits,memLevel,strategy : longint) : longint;
  128. function inflateInit2(var strm:TZStream;windowBits : longint) : longint;
  129. function zErrorpchar(err:longint):pchar;cdecl;external libz name 'zError';
  130. function zError(err:longint):string;
  131. function inflateSyncPoint(z:PZstream):longint;cdecl;external libz name 'inflateSyncPoint';
  132. function get_crc_table:pointer;cdecl;external libz name 'get_crc_table';
  133. function zlibAllocMem(AppData: Pointer; Items, Size: Integer): Pointer; cdecl;
  134. procedure zlibFreeMem(AppData, Block: Pointer); cdecl;
  135. implementation
  136. uses
  137. strings;
  138. function zlibversion : string;
  139. begin
  140. zlibversion:=strpas(zlibversionpchar);
  141. end;
  142. function deflateInit(var strm:TZStream;level : longint) : longint;
  143. begin
  144. deflateInit:=deflateInit_(strm,level,ZLIB_VERSION,sizeof(TZStream));
  145. end;
  146. function inflateInit(var strm:TZStream) : longint;
  147. begin
  148. inflateInit:=inflateInit_(strm,ZLIB_VERSION,sizeof(TZStream));
  149. end;
  150. function deflateInit2(var strm:TZStream;level,method,windowBits,memLevel,strategy : longint) : longint;
  151. begin
  152. deflateInit2:=deflateInit2_(strm,level,method,windowBits,memLevel,strategy,ZLIB_VERSION,sizeof(TZStream));
  153. end;
  154. function inflateInit2(var strm:TZStream;windowBits : longint) : longint;
  155. begin
  156. inflateInit2:=inflateInit2_(strm,windowBits,ZLIB_VERSION,sizeof(TZStream));
  157. end;
  158. function zError(err:longint):string;
  159. begin
  160. zerror:=Strpas(zErrorpchar(err));
  161. end;
  162. function zlibAllocMem(AppData: Pointer; Items, Size: Integer): Pointer; cdecl;
  163. begin
  164. Result := AllocMem(Items * Size);
  165. end;
  166. procedure zlibFreeMem(AppData, Block: Pointer); cdecl;
  167. begin
  168. FreeMem(Block);
  169. end;
  170. end.