zlib.pp 7.3 KB

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