⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zlib.pas

📁 this gcc-g++-3.3.1.tar.gz is a source file of gcc, you can learn more about gcc through this codes f
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{*******************************************************}{                                                       }{       Delphi Supplemental Components                  }{       ZLIB Data Compression Interface Unit            }{                                                       }{       Copyright (c) 1997 Borland International        }{                                                       }{*******************************************************}{ Modified for zlib 1.1.3 by Davide Moretti <dave@rimini.com }unit zlib;interfaceuses Sysutils, Classes;type  TAlloc = function (AppData: Pointer; Items, Size: Integer): Pointer;  TFree = procedure (AppData, Block: Pointer);  // Internal structure.  Ignore.  TZStreamRec = packed record    next_in: PChar;       // next input byte    avail_in: Integer;    // number of bytes available at next_in    total_in: Integer;    // total nb of input bytes read so far    next_out: PChar;      // next output byte should be put here    avail_out: Integer;   // remaining free space at next_out    total_out: Integer;   // total nb of bytes output so far    msg: PChar;           // last error message, NULL if no error    internal: Pointer;    // not visible by applications    zalloc: TAlloc;       // used to allocate the internal state    zfree: TFree;         // used to free the internal state    AppData: Pointer;     // private data object passed to zalloc and zfree    data_type: Integer;   //  best guess about the data type: ascii or binary    adler: Integer;       // adler32 value of the uncompressed data    reserved: Integer;    // reserved for future use  end;  // Abstract ancestor class  TCustomZlibStream = class(TStream)  private    FStrm: TStream;    FStrmPos: Integer;    FOnProgress: TNotifyEvent;    FZRec: TZStreamRec;    FBuffer: array [Word] of Char;  protected    procedure Progress(Sender: TObject); dynamic;    property OnProgress: TNotifyEvent read FOnProgress write FOnProgress;    constructor Create(Strm: TStream);  end;{ TCompressionStream compresses data on the fly as data is written to it, and  stores the compressed data to another stream.  TCompressionStream is write-only and strictly sequential. Reading from the  stream will raise an exception. Using Seek to move the stream pointer  will raise an exception.  Output data is cached internally, written to the output stream only when  the internal output buffer is full.  All pending output data is flushed  when the stream is destroyed.  The Position property returns the number of uncompressed bytes of  data that have been written to the stream so far.  CompressionRate returns the on-the-fly percentage by which the original  data has been compressed:  (1 - (CompressedBytes / UncompressedBytes)) * 100  If raw data size = 100 and compressed data size = 25, the CompressionRate  is 75%  The OnProgress event is called each time the output buffer is filled and  written to the output stream.  This is useful for updating a progress  indicator when you are writing a large chunk of data to the compression  stream in a single call.}  TCompressionLevel = (clNone, clFastest, clDefault, clMax);  TCompressionStream = class(TCustomZlibStream)  private    function GetCompressionRate: Single;  public    constructor Create(CompressionLevel: TCompressionLevel; Dest: TStream);    destructor Destroy; override;    function Read(var Buffer; Count: Longint): Longint; override;    function Write(const Buffer; Count: Longint): Longint; override;    function Seek(Offset: Longint; Origin: Word): Longint; override;    property CompressionRate: Single read GetCompressionRate;    property OnProgress;  end;{ TDecompressionStream decompresses data on the fly as data is read from it.  Compressed data comes from a separate source stream.  TDecompressionStream  is read-only and unidirectional; you can seek forward in the stream, but not  backwards.  The special case of setting the stream position to zero is  allowed.  Seeking forward decompresses data until the requested position in  the uncompressed data has been reached.  Seeking backwards, seeking relative  to the end of the stream, requesting the size of the stream, and writing to  the stream will raise an exception.  The Position property returns the number of bytes of uncompressed data that  have been read from the stream so far.  The OnProgress event is called each time the internal input buffer of  compressed data is exhausted and the next block is read from the input stream.  This is useful for updating a progress indicator when you are reading a  large chunk of data from the decompression stream in a single call.}  TDecompressionStream = class(TCustomZlibStream)  public    constructor Create(Source: TStream);    destructor Destroy; override;    function Read(var Buffer; Count: Longint): Longint; override;    function Write(const Buffer; Count: Longint): Longint; override;    function Seek(Offset: Longint; Origin: Word): Longint; override;    property OnProgress;  end;{ CompressBuf compresses data, buffer to buffer, in one call.   In: InBuf = ptr to compressed data       InBytes = number of bytes in InBuf  Out: OutBuf = ptr to newly allocated buffer containing decompressed data       OutBytes = number of bytes in OutBuf   }procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;                      out OutBuf: Pointer; out OutBytes: Integer);{ DecompressBuf decompresses data, buffer to buffer, in one call.   In: InBuf = ptr to compressed data       InBytes = number of bytes in InBuf       OutEstimate = zero, or est. size of the decompressed data  Out: OutBuf = ptr to newly allocated buffer containing decompressed data       OutBytes = number of bytes in OutBuf   }procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer; OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);const  zlib_version = '1.1.3';type  EZlibError = class(Exception);  ECompressionError = class(EZlibError);  EDecompressionError = class(EZlibError);function adler32(adler: Integer; buf: PChar; len: Integer): Integer;implementationconst  Z_NO_FLUSH      = 0;  Z_PARTIAL_FLUSH = 1;  Z_SYNC_FLUSH    = 2;  Z_FULL_FLUSH    = 3;  Z_FINISH        = 4;  Z_OK            = 0;  Z_STREAM_END    = 1;  Z_NEED_DICT     = 2;  Z_ERRNO         = (-1);  Z_STREAM_ERROR  = (-2);  Z_DATA_ERROR    = (-3);  Z_MEM_ERROR     = (-4);  Z_BUF_ERROR     = (-5);  Z_VERSION_ERROR = (-6);  Z_NO_COMPRESSION       =   0;  Z_BEST_SPEED           =   1;  Z_BEST_COMPRESSION     =   9;  Z_DEFAULT_COMPRESSION  = (-1);  Z_FILTERED            = 1;  Z_HUFFMAN_ONLY        = 2;  Z_DEFAULT_STRATEGY    = 0;  Z_BINARY   = 0;  Z_ASCII    = 1;  Z_UNKNOWN  = 2;  Z_DEFLATED = 8;  _z_errmsg: array[0..9] of PChar = (    'need dictionary',      // Z_NEED_DICT      (2)    'stream end',           // Z_STREAM_END     (1)    '',                     // Z_OK             (0)    'file error',           // Z_ERRNO          (-1)    'stream error',         // Z_STREAM_ERROR   (-2)    'data error',           // Z_DATA_ERROR     (-3)    'insufficient memory',  // Z_MEM_ERROR      (-4)    'buffer error',         // Z_BUF_ERROR      (-5)    'incompatible version', // Z_VERSION_ERROR  (-6)    ''  );{$L deflate.obj}{$L inflate.obj}{$L inftrees.obj}{$L trees.obj}{$L adler32.obj}{$L infblock.obj}{$L infcodes.obj}{$L infutil.obj}{$L inffast.obj}procedure _tr_init; external;procedure _tr_tally; external;procedure _tr_flush_block; external;procedure _tr_align; external;procedure _tr_stored_block; external;function adler32; external;procedure inflate_blocks_new; external;procedure inflate_blocks; external;procedure inflate_blocks_reset; external;procedure inflate_blocks_free; external;procedure inflate_set_dictionary; external;procedure inflate_trees_bits; external;procedure inflate_trees_dynamic; external;procedure inflate_trees_fixed; external;procedure inflate_codes_new; external;procedure inflate_codes; external;procedure inflate_codes_free; external;procedure _inflate_mask; external;procedure inflate_flush; external;procedure inflate_fast; external;procedure _memset(P: Pointer; B: Byte; count: Integer);cdecl;begin  FillChar(P^, count, B);end;procedure _memcpy(dest, source: Pointer; count: Integer);cdecl;begin  Move(source^, dest^, count);end;// deflate compresses datafunction deflateInit_(var strm: TZStreamRec; level: Integer; version: PChar;  recsize: Integer): Integer; external;function deflate(var strm: TZStreamRec; flush: Integer): Integer; external;function deflateEnd(var strm: TZStreamRec): Integer; external;// inflate decompresses datafunction inflateInit_(var strm: TZStreamRec; version: PChar;  recsize: Integer): Integer; external;function inflate(var strm: TZStreamRec; flush: Integer): Integer; external;function inflateEnd(var strm: TZStreamRec): Integer; external;function inflateReset(var strm: TZStreamRec): Integer; external;function zcalloc(AppData: Pointer; Items, Size: Integer): Pointer;begin  GetMem(Result, Items*Size);end;procedure zcfree(AppData, Block: Pointer);begin  FreeMem(Block);end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -