zlib-binding¶
This module creates Dylan bindings that directly reflect the zlib C library.
Constants¶
Flush values¶
Return codes for (de)compression¶
Positive values are used for special but normal events:
- $z-stream-end Constant¶
The end of the compressed data has been reached and all uncompressed output has been produced.
- Type:
Negative values are errors:
- $z-buf-error Constant¶
No progress was possible or there was not enough room in the output buffer when
$z-finish
was used.- Type:
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:
Compression strategy¶
Deflate data-type field values¶
- $z-ascii Constant¶
Default to :const:`$z-text`_ for compatibility with 1.2.2 and earlier.
- Type:
Others¶
- $z-deflated Constant¶
The deflate compression method (the only one supported in this version).
- Type:
- $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:
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.
- 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:
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.
z-compress-bound
¶
- z-compress-bound Function¶
Returns an upper bound on the compressed size after
z-compress
orz-compress-2
on source-length bytes. It would be used before az-compress
orz-compress-2
call to allocate the destination buffer.
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.