ZipCompressZlib Function

Action

Compresses a data buffer in zLib format. The resulting zipped buffer can be unzipped with the ZipUncompressZlib function. The ZipCompressZlib function uses the deflate compression algorithm and prepends the zLib header.

Include file

Zip.bdh

Syntax

ZipCompressZLib( in  sSource    : string,
                 in  nSrcLen    : number,
                 out sDest      : string,
                 in  nDstLen    : number optional,
                 out nOutLen    : number optional,
                 in  nCompLevel : number optional ) : boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
sSource Source buffer to be compressed in zLib format.
nSrcLen Length of source buffer.
sDest Destination buffer used to store the compressed data.
nDstLen Length of destination buffer (optional).
nOutLen Number of bytes used in the destination buffer to store the compressed data (optional).
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;
  nUnzipped: number;  

begin
  nUnzipped := sizeof(sUnzipped);
  for i := 1 to nUnzipped do
    sUnzipped[i] := chr(ord('a') + ((i-1) mod 26));
end;
  ZipCompressZlib(sUnzipped, STRING_COMPLETE, sZipped);
  WriteLn("Size of unzipped buffer: " + string (Binlen(sUnzipped)));
  WriteLn("Size of zipped buffer: " + string (Binlen(sZipped)));
  ZipUncompressZlib(sZipped, binlen(sZipped), sUnzipped);

  WriteData(sUnzipped);
end TMain;

Output:

Size of unzipped buffer: 254

Size of zipped buffer:   37

abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst