zlib-binding

This module creates Dylan bindings that directly reflect the zlib C library.

Constants

Flush values

$z-no-flush Constant
Type:

<integer>

$z-partial-flush Constant
Type:

<integer>

$z-sync-flush Constant
Type:

<integer>

$z-full-flush Constant
Type:

<integer>

$z-finish Constant
Type:

<integer>

$z-block Constant
Type:

<integer>

$z-trees Constant
Type:

<integer>

Return codes for (de)compression

Positive values are used for special but normal events:

$z-ok Constant

The operation was a success.

Type:

<integer>

$z-stream-end Constant

The end of the compressed data has been reached and all uncompressed output has been produced.

Type:

<integer>

$z-need-dict Constant

A preset dictionary is needed.

Type:

<integer>

Negative values are errors:

$z-errno Constant
Type:

<integer>

$z-stream-error Constant

The compression level is not valid.

Type:

<integer>

$z-data-error Constant
Type:

<integer>

$z-mem-error Constant

There was not enough memory.

Type:

<integer>

$z-buf-error Constant

No progress was possible or there was not enough room in the output buffer when $z-finish was used.

Type:

<integer>

$z-version-error Constant

The z library version is incompatible with the version assumed by the caller.

Type:

<integer>

Compression levels

The compression levels are a number between 0 and 9. 1 gives best speed, 9 gives best compression, 0 gives no compression at all (all the input is simply copied a block at a time).

$z-no-compression Constant

Uses no compression at all (all the input is simply copied a block at a time).

Type:

<integer>

$z-best-speed Constant

Gives better speed at the cost of less compression.

Type:

<integer>

$z-best-compression Constant

Best compression but less speed.

Type:

<integer>

$z-default-compression Constant

A compromise between speed and compression (currently equivalent to level 6).

Type:

<integer>

Compression strategy

$z-filtered Constant
Type:

<integer>

$z-huffman-only Constant
Type:

<integer>

$z-rle Constant
Type:

<integer>

$z-fixed Constant
Type:

<integer>

$z-default-strategy Constant
Type:

<integer>

Deflate data-type field values

$z-binary Constant
Type:

<integer>

$z-text Constant
Type:

<integer>

$z-ascii Constant

Default to :const:`$z-text`_ for compatibility with 1.2.2 and earlier.

Type:

<integer>

$z-unknown Constant
Type:

<integer>

Others

$z-deflated Constant

The deflate compression method (the only one supported in this version).

Type:

<integer>

$z-null Constant

For initialization, null pointer.

Utility functions

These functions are implemented on top of the basic zlib stream-oriented functions. To simplify the interface, some default options are assumed (compression level and memory usage).

z-compress

z-compress Function

Compress a string.

Signature:

z-compress string destination-length source source-length => (return-code)

Parameters:
  • destination – Destination buffer of the compressed string. An instance of <C-buffer-offset>

  • destination-length – Byte length of the destination buffer, which must be at least the value returned by z-compress-bound. At exit it contains the actual size of compressed data. An instance of <C-unsigned-long*>

  • source – String to compress. An instance of <string>

  • source-length – Byte length of the source buffer. An instance of <C-unsigned-long>

Values:
Discussion:

It’s equivalent to z-compress-2 with a level parameter $z-default-compression.

z-compress-2

z-compress-2 Function

Compress a string.

Signature:

z-compress-2 string destination-length source source-length level => (return-code)

Parameters:
  • destination – Destination buffer of the compressed string. An instance of <C-buffer-offset>

  • destination-length – Byte length of the destination buffer, which must be at least the value returned by z-compress-bound. At exit it contains the actual size of compressed data. An instance of <integer>

  • source – String to compress. An instance of <string>

  • source-length – Byte length of the source buffer. An instance of <C-unsigned-long>

  • level

    An instance of <integer>. The compression level must be $z-default-compression, or a number between 0 and 9.

    seealso:

    See Compression levels.

Values:

z-compress-bound

z-compress-bound Function

Returns an upper bound on the compressed size after z-compress or z-compress-2 on source-length bytes. It would be used before a z-compress or z-compress-2 call to allocate the destination buffer.

Signature:

z-compress-bound source-length => (return-code)

Parameters:
  • source-length – An instance of <integer>. Is the length in bytes of the source buffer.

Values:
  • return-code – An instance of <integer>. Number of bytes of the upper bound.

z-uncompress

z-uncompress Function

Uncompress a previously compressed string.

Signature:

z-uncompress destination destination-length source source-length => (return-code)

Parameters:
  • destination – An instance of <string>. Destination of uncompressed source.

  • destination-length – An instance of <integer>. Upon entry is the total size of the destination buffer, which must be large enough to hold the entire uncompressed data. The size of the uncompressed data must have been saved previously by the compressor and transmitted to the decompressor by some mechanism outside the scope of this compression library. Upon exit, destination-length is the actual size of the compressed data.

  • source – An instance of <string>. Compressed string.

  • source-length – An instance of <integer>. Byte length of the source buffer.

Values:
  • return-code – An instance of <integer>. Returns $z-ok if success, $z-mem-error if there was not enough memory, $z-buf-error if there was not enough room in the output buffer, or $z-data-error if the input data was corrupted or incomplete. In the case where there is not enough room, this function will fill the output buffer with the uncompressed data up to that point.

z-uncompress-2

z-uncompress-2 Function

Uncompress a previously compressed string. Same as z-uncompress, except that source-length is a pointer, where the length of the source is source-length. On return source-length is the number of source bytes consumed.

Signature:

z-uncompress-2 destination destination-length source source-length => (return-code)

Parameters:
  • destination – An instance of <string>. Destination of uncompressed source.

  • destination-length – An instance of <integer>. Upon entry is the total size of the destination buffer, which must be large enough to hold the entire uncompressed data. The size of the uncompressed data must have been saved previously by the compressor and transmitted to the decompressor by some mechanism outside the scope of this compression library. Upon exit, destination-length is the actual size of the compressed data.

  • source – An instance of <string>. Compressed string.

  • source-length – An instance of <integer>. On return is the number of source bytes consumed.

Values:
  • return-code – An instance of <integer>. Returns $z-ok if success, $z-mem-error if there was not enough memory, $z-buf-error if there was not enough room in the output buffer, or $z-data-error if the input data was corrupted or incomplete. In the case where there is not enough room, this function will fill the output buffer with the uncompressed data up to that point.