zlib.pp 6.7 KB

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