ZipCompressGzip2 Function

Action

Compresses a data buffer in gzip format. The resulting zipped buffer can be unzipped with the ZipUncompressGzip2 function or any gzip unzipper tool. The ZipCompressGzip2 function uses the deflate compression algorithm.

Include file

Zip.bdh

Syntax

ZipCompressGzip2( in  sSource    : string,
                  out sDest      : string,
                  in  nCompLevel : number optional ) : boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
sSource Source buffer to be compressed in gzip format.
sDest Destination buffer used to store the compressed data.
nCompLevel

Level of compression. The compression level must be ZIP_COMPRESSION_DEFAULT, or between 0 and 9 (optional):

  • 1 gives best speed
  • 9 gives best compression
  • 0 gives no compression at all
  • ZIP_COMPRESSION_DEFAULT means a default compromise between speed and compression (currently equivalent to level 6).

Example

transaction TMain
var
  sUnzipped : string;
  sZipped   : string;
  i         : number;
  
begin  
  for i := 1 to nUnzipped do
    sUnzipped[i] := chr(ord('a') + ((i-1) mod 26));
end;

  ZipCompressGzip2(sUnzipped, sZipped);
  WriteLn("Size of unzipped buffer: " + string(Binlen(sUnzipped)));
  WriteLn("Size of zipped buffer: " + string(Binlen(sZipped)));
  ZipUncompressGzip2(sZipped, binlen(sZipped), sUnzipped);                   

  WriteData(sUnzipped)
endTMain;

Output:

Size of unzipped buffer: 254

Size of zipped buffer:   49

abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst