zlib.pp 7.4 KB

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