kusano fc6ab3
(* zlibpas -- Pascal interface to the zlib data compression library
kusano fc6ab3
 *
kusano fc6ab3
 * Copyright (C) 2003 Cosmin Truta.
kusano fc6ab3
 * Derived from original sources by Bob Dellaca.
kusano fc6ab3
 * For conditions of distribution and use, see copyright notice in readme.txt
kusano fc6ab3
 *)
kusano fc6ab3
kusano fc6ab3
unit zlibpas;
kusano fc6ab3
kusano fc6ab3
interface
kusano fc6ab3
kusano fc6ab3
const
kusano fc6ab3
  ZLIB_VERSION = '1.2.8';
kusano fc6ab3
  ZLIB_VERNUM  = $1280;
kusano fc6ab3
kusano fc6ab3
type
kusano fc6ab3
  alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
kusano fc6ab3
                 cdecl;
kusano fc6ab3
  free_func  = procedure(opaque, address: Pointer);
kusano fc6ab3
                 cdecl;
kusano fc6ab3
kusano fc6ab3
  in_func    = function(opaque: Pointer; var buf: PByte): Integer;
kusano fc6ab3
                 cdecl;
kusano fc6ab3
  out_func   = function(opaque: Pointer; buf: PByte; size: Integer): Integer;
kusano fc6ab3
                 cdecl;
kusano fc6ab3
kusano fc6ab3
  z_streamp = ^z_stream;
kusano fc6ab3
  z_stream = packed record
kusano fc6ab3
    next_in: PChar;       (* next input byte *)
kusano fc6ab3
    avail_in: Integer;    (* number of bytes available at next_in *)
kusano fc6ab3
    total_in: LongInt;    (* total nb of input bytes read so far *)
kusano fc6ab3
kusano fc6ab3
    next_out: PChar;      (* next output byte should be put there *)
kusano fc6ab3
    avail_out: Integer;   (* remaining free space at next_out *)
kusano fc6ab3
    total_out: LongInt;   (* total nb of bytes output so far *)
kusano fc6ab3
kusano fc6ab3
    msg: PChar;           (* last error message, NULL if no error *)
kusano fc6ab3
    state: Pointer;       (* not visible by applications *)
kusano fc6ab3
kusano fc6ab3
    zalloc: alloc_func;   (* used to allocate the internal state *)
kusano fc6ab3
    zfree: free_func;     (* used to free the internal state *)
kusano fc6ab3
    opaque: Pointer;      (* private data object passed to zalloc and zfree *)
kusano fc6ab3
kusano fc6ab3
    data_type: Integer;   (* best guess about the data type: ascii or binary *)
kusano fc6ab3
    adler: LongInt;       (* adler32 value of the uncompressed data *)
kusano fc6ab3
    reserved: LongInt;    (* reserved for future use *)
kusano fc6ab3
  end;
kusano fc6ab3
kusano fc6ab3
  gz_headerp = ^gz_header;
kusano fc6ab3
  gz_header = packed record
kusano fc6ab3
    text: Integer;        (* true if compressed data believed to be text *)
kusano fc6ab3
    time: LongInt;        (* modification time *)
kusano fc6ab3
    xflags: Integer;      (* extra flags (not used when writing a gzip file) *)
kusano fc6ab3
    os: Integer;          (* operating system *)
kusano fc6ab3
    extra: PChar;         (* pointer to extra field or Z_NULL if none *)
kusano fc6ab3
    extra_len: Integer;   (* extra field length (valid if extra != Z_NULL) *)
kusano fc6ab3
    extra_max: Integer;   (* space at extra (only when reading header) *)
kusano fc6ab3
    name: PChar;          (* pointer to zero-terminated file name or Z_NULL *)
kusano fc6ab3
    name_max: Integer;    (* space at name (only when reading header) *)
kusano fc6ab3
    comment: PChar;       (* pointer to zero-terminated comment or Z_NULL *)
kusano fc6ab3
    comm_max: Integer;    (* space at comment (only when reading header) *)
kusano fc6ab3
    hcrc: Integer;        (* true if there was or will be a header crc *)
kusano fc6ab3
    done: Integer;        (* true when done reading gzip header *)
kusano fc6ab3
  end;
kusano fc6ab3
kusano fc6ab3
(* constants *)
kusano fc6ab3
const
kusano fc6ab3
  Z_NO_FLUSH      = 0;
kusano fc6ab3
  Z_PARTIAL_FLUSH = 1;
kusano fc6ab3
  Z_SYNC_FLUSH    = 2;
kusano fc6ab3
  Z_FULL_FLUSH    = 3;
kusano fc6ab3
  Z_FINISH        = 4;
kusano fc6ab3
  Z_BLOCK         = 5;
kusano fc6ab3
  Z_TREES         = 6;
kusano fc6ab3
kusano fc6ab3
  Z_OK            =  0;
kusano fc6ab3
  Z_STREAM_END    =  1;
kusano fc6ab3
  Z_NEED_DICT     =  2;
kusano fc6ab3
  Z_ERRNO         = -1;
kusano fc6ab3
  Z_STREAM_ERROR  = -2;
kusano fc6ab3
  Z_DATA_ERROR    = -3;
kusano fc6ab3
  Z_MEM_ERROR     = -4;
kusano fc6ab3
  Z_BUF_ERROR     = -5;
kusano fc6ab3
  Z_VERSION_ERROR = -6;
kusano fc6ab3
kusano fc6ab3
  Z_NO_COMPRESSION       =  0;
kusano fc6ab3
  Z_BEST_SPEED           =  1;
kusano fc6ab3
  Z_BEST_COMPRESSION     =  9;
kusano fc6ab3
  Z_DEFAULT_COMPRESSION  = -1;
kusano fc6ab3
kusano fc6ab3
  Z_FILTERED            = 1;
kusano fc6ab3
  Z_HUFFMAN_ONLY        = 2;
kusano fc6ab3
  Z_RLE                 = 3;
kusano fc6ab3
  Z_FIXED               = 4;
kusano fc6ab3
  Z_DEFAULT_STRATEGY    = 0;
kusano fc6ab3
kusano fc6ab3
  Z_BINARY   = 0;
kusano fc6ab3
  Z_TEXT     = 1;
kusano fc6ab3
  Z_ASCII    = 1;
kusano fc6ab3
  Z_UNKNOWN  = 2;
kusano fc6ab3
kusano fc6ab3
  Z_DEFLATED = 8;
kusano fc6ab3
kusano fc6ab3
(* basic functions *)
kusano fc6ab3
function zlibVersion: PChar;
kusano fc6ab3
function deflateInit(var strm: z_stream; level: Integer): Integer;
kusano fc6ab3
function deflate(var strm: z_stream; flush: Integer): Integer;
kusano fc6ab3
function deflateEnd(var strm: z_stream): Integer;
kusano fc6ab3
function inflateInit(var strm: z_stream): Integer;
kusano fc6ab3
function inflate(var strm: z_stream; flush: Integer): Integer;
kusano fc6ab3
function inflateEnd(var strm: z_stream): Integer;
kusano fc6ab3
kusano fc6ab3
(* advanced functions *)
kusano fc6ab3
function deflateInit2(var strm: z_stream; level, method, windowBits,
kusano fc6ab3
                      memLevel, strategy: Integer): Integer;
kusano fc6ab3
function deflateSetDictionary(var strm: z_stream; const dictionary: PChar;
kusano fc6ab3
                              dictLength: Integer): Integer;
kusano fc6ab3
function deflateCopy(var dest, source: z_stream): Integer;
kusano fc6ab3
function deflateReset(var strm: z_stream): Integer;
kusano fc6ab3
function deflateParams(var strm: z_stream; level, strategy: Integer): Integer;
kusano fc6ab3
function deflateTune(var strm: z_stream; good_length, max_lazy, nice_length, max_chain: Integer): Integer;
kusano fc6ab3
function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt;
kusano fc6ab3
function deflatePending(var strm: z_stream; var pending: Integer; var bits: Integer): Integer;
kusano fc6ab3
function deflatePrime(var strm: z_stream; bits, value: Integer): Integer;
kusano fc6ab3
function deflateSetHeader(var strm: z_stream; head: gz_header): Integer;
kusano fc6ab3
function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
kusano fc6ab3
function inflateSetDictionary(var strm: z_stream; const dictionary: PChar;
kusano fc6ab3
                              dictLength: Integer): Integer;
kusano fc6ab3
function inflateSync(var strm: z_stream): Integer;
kusano fc6ab3
function inflateCopy(var dest, source: z_stream): Integer;
kusano fc6ab3
function inflateReset(var strm: z_stream): Integer;
kusano fc6ab3
function inflateReset2(var strm: z_stream; windowBits: Integer): Integer;
kusano fc6ab3
function inflatePrime(var strm: z_stream; bits, value: Integer): Integer;
kusano fc6ab3
function inflateMark(var strm: z_stream): LongInt;
kusano fc6ab3
function inflateGetHeader(var strm: z_stream; var head: gz_header): Integer;
kusano fc6ab3
function inflateBackInit(var strm: z_stream;
kusano fc6ab3
                         windowBits: Integer; window: PChar): Integer;
kusano fc6ab3
function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer;
kusano fc6ab3
                     out_fn: out_func; out_desc: Pointer): Integer;
kusano fc6ab3
function inflateBackEnd(var strm: z_stream): Integer;
kusano fc6ab3
function zlibCompileFlags: LongInt;
kusano fc6ab3
kusano fc6ab3
(* utility functions *)
kusano fc6ab3
function compress(dest: PChar; var destLen: LongInt;
kusano fc6ab3
                  const source: PChar; sourceLen: LongInt): Integer;
kusano fc6ab3
function compress2(dest: PChar; var destLen: LongInt;
kusano fc6ab3
                  const source: PChar; sourceLen: LongInt;
kusano fc6ab3
                  level: Integer): Integer;
kusano fc6ab3
function compressBound(sourceLen: LongInt): LongInt;
kusano fc6ab3
function uncompress(dest: PChar; var destLen: LongInt;
kusano fc6ab3
                    const source: PChar; sourceLen: LongInt): Integer;
kusano fc6ab3
kusano fc6ab3
(* checksum functions *)
kusano fc6ab3
function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt;
kusano fc6ab3
function adler32_combine(adler1, adler2, len2: LongInt): LongInt;
kusano fc6ab3
function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt;
kusano fc6ab3
function crc32_combine(crc1, crc2, len2: LongInt): LongInt;
kusano fc6ab3
kusano fc6ab3
(* various hacks, don't look :) *)
kusano fc6ab3
function deflateInit_(var strm: z_stream; level: Integer;
kusano fc6ab3
                      const version: PChar; stream_size: Integer): Integer;
kusano fc6ab3
function inflateInit_(var strm: z_stream; const version: PChar;
kusano fc6ab3
                      stream_size: Integer): Integer;
kusano fc6ab3
function deflateInit2_(var strm: z_stream;
kusano fc6ab3
                       level, method, windowBits, memLevel, strategy: Integer;
kusano fc6ab3
                       const version: PChar; stream_size: Integer): Integer;
kusano fc6ab3
function inflateInit2_(var strm: z_stream; windowBits: Integer;
kusano fc6ab3
                       const version: PChar; stream_size: Integer): Integer;
kusano fc6ab3
function inflateBackInit_(var strm: z_stream;
kusano fc6ab3
                          windowBits: Integer; window: PChar;
kusano fc6ab3
                          const version: PChar; stream_size: Integer): Integer;
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
implementation
kusano fc6ab3
kusano fc6ab3
{$L adler32.obj}
kusano fc6ab3
{$L compress.obj}
kusano fc6ab3
{$L crc32.obj}
kusano fc6ab3
{$L deflate.obj}
kusano fc6ab3
{$L infback.obj}
kusano fc6ab3
{$L inffast.obj}
kusano fc6ab3
{$L inflate.obj}
kusano fc6ab3
{$L inftrees.obj}
kusano fc6ab3
{$L trees.obj}
kusano fc6ab3
{$L uncompr.obj}
kusano fc6ab3
{$L zutil.obj}
kusano fc6ab3
kusano fc6ab3
function adler32; external;
kusano fc6ab3
function adler32_combine; external;
kusano fc6ab3
function compress; external;
kusano fc6ab3
function compress2; external;
kusano fc6ab3
function compressBound; external;
kusano fc6ab3
function crc32; external;
kusano fc6ab3
function crc32_combine; external;
kusano fc6ab3
function deflate; external;
kusano fc6ab3
function deflateBound; external;
kusano fc6ab3
function deflateCopy; external;
kusano fc6ab3
function deflateEnd; external;
kusano fc6ab3
function deflateInit_; external;
kusano fc6ab3
function deflateInit2_; external;
kusano fc6ab3
function deflateParams; external;
kusano fc6ab3
function deflatePending; external;
kusano fc6ab3
function deflatePrime; external;
kusano fc6ab3
function deflateReset; external;
kusano fc6ab3
function deflateSetDictionary; external;
kusano fc6ab3
function deflateSetHeader; external;
kusano fc6ab3
function deflateTune; external;
kusano fc6ab3
function inflate; external;
kusano fc6ab3
function inflateBack; external;
kusano fc6ab3
function inflateBackEnd; external;
kusano fc6ab3
function inflateBackInit_; external;
kusano fc6ab3
function inflateCopy; external;
kusano fc6ab3
function inflateEnd; external;
kusano fc6ab3
function inflateGetHeader; external;
kusano fc6ab3
function inflateInit_; external;
kusano fc6ab3
function inflateInit2_; external;
kusano fc6ab3
function inflateMark; external;
kusano fc6ab3
function inflatePrime; external;
kusano fc6ab3
function inflateReset; external;
kusano fc6ab3
function inflateReset2; external;
kusano fc6ab3
function inflateSetDictionary; external;
kusano fc6ab3
function inflateSync; external;
kusano fc6ab3
function uncompress; external;
kusano fc6ab3
function zlibCompileFlags; external;
kusano fc6ab3
function zlibVersion; external;
kusano fc6ab3
kusano fc6ab3
function deflateInit(var strm: z_stream; level: Integer): Integer;
kusano fc6ab3
begin
kusano fc6ab3
  Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream));
kusano fc6ab3
end;
kusano fc6ab3
kusano fc6ab3
function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel,
kusano fc6ab3
                      strategy: Integer): Integer;
kusano fc6ab3
begin
kusano fc6ab3
  Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
kusano fc6ab3
                          ZLIB_VERSION, sizeof(z_stream));
kusano fc6ab3
end;
kusano fc6ab3
kusano fc6ab3
function inflateInit(var strm: z_stream): Integer;
kusano fc6ab3
begin
kusano fc6ab3
  Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream));
kusano fc6ab3
end;
kusano fc6ab3
kusano fc6ab3
function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
kusano fc6ab3
begin
kusano fc6ab3
  Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream));
kusano fc6ab3
end;
kusano fc6ab3
kusano fc6ab3
function inflateBackInit(var strm: z_stream;
kusano fc6ab3
                         windowBits: Integer; window: PChar): Integer;
kusano fc6ab3
begin
kusano fc6ab3
  Result := inflateBackInit_(strm, windowBits, window,
kusano fc6ab3
                             ZLIB_VERSION, sizeof(z_stream));
kusano fc6ab3
end;
kusano fc6ab3
kusano fc6ab3
function _malloc(Size: Integer): Pointer; cdecl;
kusano fc6ab3
begin
kusano fc6ab3
  GetMem(Result, Size);
kusano fc6ab3
end;
kusano fc6ab3
kusano fc6ab3
procedure _free(Block: Pointer); cdecl;
kusano fc6ab3
begin
kusano fc6ab3
  FreeMem(Block);
kusano fc6ab3
end;
kusano fc6ab3
kusano fc6ab3
procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl;
kusano fc6ab3
begin
kusano fc6ab3
  FillChar(P^, count, B);
kusano fc6ab3
end;
kusano fc6ab3
kusano fc6ab3
procedure _memcpy(dest, source: Pointer; count: Integer); cdecl;
kusano fc6ab3
begin
kusano fc6ab3
  Move(source^, dest^, count);
kusano fc6ab3
end;
kusano fc6ab3
kusano fc6ab3
end.