Scieneer Common Lisp 1.3.9 online documentation

GZIP compression

Introduction

A gzip output stream and a gunzip input stream are provided for writing and reading gzip compressed files or to sending and receiving gzip compressed content over sockets. Functions are also provided to gzip compress or decompress byte vectors.

Gzip compression streams

ext:make-gzip-output-stream stream &key level element-type external-format time file-name close-stream-p window-bits mem-level buffering pathname out-buffer-size finalizep[Function]

Create a gzip compression stream that writes to the given target binary stream.

:level
The compression level between 0 and 9, with a default of 6. Higher compression levels may give greater compression but at the expense of longer compression times.
:element-type
Indicates the element type to use. Only the character and '(unsigned-byte 8) types are supported. The default is to create a binary '(unsigned-byte 8) stream.
:external-format
The external character format to use. The default value is :default for which the value of ext:*default-external-format* is used.
:time
A time in universal time format to write into the gzip header. The default is the current time.
:file-name
An optional file name to write to the gzip header.
:close-stream-p
When true the target stream is closed when this stream is closed. By default the target stream is not closed.
:buffering
Indicates the kind of output buffer flushing to use which may be one of: :none, :line, or the default :full. Line buffering is only applicable to character streams.
:pathname
When true, the returned stream will be a subclass of the class file-stream. This should generally be true if the stream is a file-stream.

ext:gzip-output-stream[Class]

Class precedence list:

ext:gzip-output-stream, ext:encapsulating-binary-output-stream, ext:encapsulating-output-stream, ext:encapsulating-binary-stream, ext:encapsulating-stream, ext:binary-output-stream, ext:output-stream, ext:binary-stream, stream, standard-object, ext:instance, t.

Base class for gzip compression streams.

ext:gzip-output-stream-stream stream[Function]

Returns the target binary stream associated with the given gzip compression stream.

ext:make-gunzip-input-stream stream &key element-type external-format close-stream-p allow-concatenated-p in-buffer-size finalizep pathname[Function]

Create a gzip decompression stream that reads from the given source binary stream. Once the stream is open the header time and optional file name may be obtained via ext:gunzip-input-stream-time and ext:gunzip-input-stream-file-name respectively.

:element-type
Indicates the element type to use. Only the character and '(unsigned-byte 8) types are supported. The default is to create an binary '(unsigned-byte 8) stream.
:external-format
The external character format to use. The default value is :default for which the value of ext:*default-external-format* is used.
:close-stream-p
If true then the target stream is closed when this stream is closed.
:allow-concatenated-p
When true, read multiple gzip files concatenated together as a single stream. Otherwise an EOF is returned at the end of the first file in the source stream.
:pathname
When true, the returned stream will be a subclass of the class file-stream. This should generally be true if the stream is a file-stream.

ext:gunzip-input-stream[Class]

Class precedence list:

ext:gunzip-input-stream, ext:encapsulating-binary-input-stream, ext:encapsulating-input-stream, ext:encapsulating-binary-stream, ext:encapsulating-stream, ext:binary-input-stream, ext:input-stream, ext:binary-stream, stream, standard-object, ext:instance, t.

Base class for gzip decompression streams.

ext:gunzip-input-stream-file-name stream[Function]

Return the optional file name from last the gzip stream header, otherwise nil.

ext:gunzip-input-stream-stream stream[Function]

Returns the source binary stream associated with the given gunzip decompression stream.

ext:gunzip-input-stream-time stream[Function]

Return the time from last the gzip stream header in universal time format.


Gzip compression of byte vectors.

ext:gzip-bytes bytes &key start end level time file-name initial-length[Function]

Gzip compress the bytes vector from the start to end positions, returning a new compressed byte vector. The compression level may be between 0 and 9, and defaults to 6, with higher compression levels giving greater compression at the expense of longer compression times. An initial-length hint may be given which can help reduce consing growing the result vector. A file time in universal time format may be given which is stored in the gzip header and defaults to the current time. An optional file-name may also be given to be written into the header.

ext:gunzip-bytes bytes &key start end initial-length maximum-length allow-concatenated-p[Function]

Inflate the gzipped bytes vector from the start to the end position, returning three values: the inflated bytes, the header time and the header file name if applicable. An initial-length hint may be given which can help reduce consing growing the result vector. A maximum-length may be specified to protect against a blowout, and an error is signaled if this is exceeded. Only the first gzipped file in the bytes is inflated by default, but if the input contains multiple concatenated gzipped files then they will all be inflated when the :allow-concatenated-p argument is true.