The zlib command provides access to the compression and check-summing facilities of the Zlib library by
Jean-loup Gailly and Mark Adler. It has the following subcommands.
COMPRESSIONSUBCOMMANDSzlibcompressstring ?level?
Returns the zlib-format compressed binary data of the binary string in string. If present, level
gives the compression level to use (from 0, which is uncompressed, to 9, maximally compressed).
zlibdecompressstring ?bufferSize?
Returns the uncompressed version of the raw compressed binary data in string. If present,
bufferSize is a hint as to what size of buffer is to be used to receive the data.
zlibdeflatestring ?level?
Returns the raw compressed binary data of the binary string in string. If present, level gives
the compression level to use (from 0, which is uncompressed, to 9, maximally compressed).
zlibgunzipstring ?-headerVarvarName?
Return the uncompressed contents of binary string string, which must have been in gzip format. If
-headerVar is given, store a dictionary describing the contents of the gzip header in the variable
called varName. The keys of the dictionary that may be present are:
comment
The comment field from the header, if present.
crc A boolean value describing whether a CRC of the header is computed.
filename
The filename field from the header, if present.
os The operating system type code field from the header (if not the QW unknown value). See RFC
1952 for the meaning of these codes.
size The size of the uncompressed data.
time The time field from the header if non-zero, expected to be time that the file named by the
filename field was modified. Suitable for use with clockformat.
type The type of the uncompressed data (binary or text) if known.
zlibgzipstring ?-levellevel? ?-headerdict?
Return the compressed contents of binary string string in gzip format. If -level is given, level
gives the compression level to use (from 0, which is uncompressed, to 9, maximally compressed). If
-header is given, dict is a dictionary containing values used for the gzip header. The following
keys may be defined:
comment
Add the given comment to the header of the gzip-format data.
crc A boolean saying whether to compute a CRC of the header. Note that if the data is to be
interchanged with the gzip program, a header CRC should not be computed.
filename
The name of the file that the data to be compressed came from.
os The operating system type code, which should be one of the values described in RFC 1952.
time The time that the file named in the filename key was last modified. This will be in the
same as is returned by clockseconds or filemtime.
type The type of the data being compressed, being binary or text.
zlibinflatestring ?bufferSize?
Returns the uncompressed version of the raw compressed binary data in string. If present,
bufferSize is a hint as to what size of buffer is to be used to receive the data.
CHANNELSUBCOMMANDzlibpushmodechannel ?options...?
Pushes a compressing or decompressing transformation onto the channel channel. The transformation
can be removed again with chanpop. The mode argument determines what type of transformation is
pushed; the following are supported:
compress
The transformation will be a compressing transformation that produces zlib-format data on
channel, which must be writable.
decompress
The transformation will be a decompressing transformation that reads zlib-format data from
channel, which must be readable.
deflate
The transformation will be a compressing transformation that produces raw compressed data
on channel, which must be writable.
gunzip The transformation will be a decompressing transformation that reads gzip-format data from
channel, which must be readable.
gzip The transformation will be a compressing transformation that produces gzip-format data on
channel, which must be writable.
inflate
The transformation will be a decompressing transformation that reads raw compressed data
from channel, which must be readable.
The following options may be set when creating a transformation via the “options...” to the zlibpush command:
-dictionarybinData
Sets the compression dictionary to use when working with compressing or decompressing the 2
data to be binData. Not valid for transformations that work with gzip-format data. The 2
dictionary should consist of strings (byte sequences) that are likely to be encountered 2
later in the data to be compressed, with the most commonly used strings preferably put 2
towards the end of the dictionary. Tcl provides no mechanism for choosing a good such 2
dictionary for a particular data sequence.
-headerdictionary
Passes a description of the gzip header to create, in the same format that zlibgzip
understands.
-levelcompressionLevel
How hard to compress the data. Must be an integer from 0 (uncompressed) to 9 (maximally
compressed).
-limitreadaheadLimit
The maximum number of bytes ahead to read when decompressing.
This option has become irrelevant. It was originally introduced to prevent Tcl from reading
beyond the end of a compressed stream in multi-stream channels to ensure that the data
after was left alone for further reading, at the cost of speed.
Tcl now automatically returns any bytes it has read beyond the end of a compressed stream
back to the channel, making them appear as unread to further readers.
Both compressing and decompressing channel transformations add extra configuration options that
may be accessed through chanconfigure. The options are:
-checksumchecksum
This read-only option gets the current checksum for the uncompressed data that the
compression engine has seen so far. It is valid for both compressing and decompressing
transforms, but not for the raw inflate and deflate formats. The compression algorithm
depends on what format is being produced or consumed.
-dictionarybinData
This read-write options gets or sets the initial compression dictionary to use when working 2
with compressing or decompressing the data to be binData. It is not valid for 2
transformations that work with gzip-format data, and should not normally be set on 2
compressing transformations other than at the point where the transformation is stacked. 2
Note that this cannot be used to get the current active compression dictionary mid-stream, 2
as that information is not exposed by the underlying library.
-flushtype
This write-only operation flushes the current state of the compressor to the underlying
channel. It is only valid for compressing transformations. The type must be either sync or
full for a normal flush or an expensive flush respectively. Flushing degrades the
compression ratio, but makes it easier for a decompressor to recover more of the file in
the case of data corruption.
-headerdictionary
This read-only option, only valid for decompressing transforms that are processing gzip-
format data, returns the dictionary describing the header read off the data stream.
-limitreadaheadLimit
This read-write option is used by decompressing channels to control the maximum number of
bytes ahead to read from the underlying data source. See above for more information.
STREAMINGSUBCOMMANDzlibstreammode ?options?
Creates a streaming compression or decompression command based on the mode, and return the name of
the command. For a description of how that command works, see STREAMINGINSTANCECOMMAND below.
The following modes and options are supported:
zlibstreamcompress ?-dictionarybindata? ?-levellevel?
The stream will be a compressing stream that produces zlib-format output, using compression
level level (if specified) which will be an integer from 0 to 9, and the compression 2
dictionary bindata (if specified).
zlibstreamdecompress ?-dictionarybindata?
The stream will be a decompressing stream that takes zlib-format input and produces
uncompressed output. If bindata is supplied, it is a compression dictionary to use if 2
required.
zlibstreamdeflate ?-dictionarybindata? ?-levellevel?
The stream will be a compressing stream that produces raw output, using compression level
level (if specified) which will be an integer from 0 to 9, and the compression dictionary 2
bindata (if specified). Note that the raw compressed data includes no metadata about what 2
compression dictionary was used, if any; that is a feature of the zlib-format data.
zlibstreamgunzip
The stream will be a decompressing stream that takes gzip-format input and produces
uncompressed output.
zlibstreamgzip ?-headerheader? ?-levellevel?
The stream will be a compressing stream that produces gzip-format output, using compression
level level (if specified) which will be an integer from 0 to 9, and the header descriptor
dictionary header (if specified; for keys see zlibgzip).
zlibstreaminflate ?-dictionarybindata?
The stream will be a decompressing stream that takes raw compressed input and produces
uncompressed output. If bindata is supplied, it is a compression dictionary to use. Note 2
that there are no checks in place to determine whether the compression dictionary is 2
correct.
CHECKSUMMINGSUBCOMMANDSzlibadler32string ?initValue?
Compute a checksum of binary string string using the Adler-32 algorithm. If given, initValue is
used to initialize the checksum engine.
zlibcrc32string ?initValue?
Compute a checksum of binary string string using the CRC-32 algorithm. If given, initValue is
used to initialize the checksum engine.