zlib.pp 7.5 KB

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