tango.io.compress.ZlibStream

License:

BSD style: see license.txt

Author:

Daniel Keep

Version:

Feb 08: Added support for different stream encodings, removed old "window bits" ctors. Dec 07: Added support for "window bits", needed for Zip support. Jul 07: Initial release.
class ZlibInput : InputFilter #
This input filter can be used to perform decompression of zlib streams.
enum Encoding #
This enumeration allows you to specify the encoding of the compressed stream.
Guess #
The code should attempt to automatically determine what the encoding of the stream should be. Note that this cannot detect the case where the stream was compressed with no encoding.
Zlib #
Stream has zlib encoding.
Gzip #
Stream has gzip encoding.
None #
Stream has no encoding.
this(InputStream stream, Encoding encoding, int windowBits = WINDOWBITS_DEFAULT) #
this(InputStream stream) #
Constructs a new zlib decompression filter. You need to pass in the stream that the decompression filter will read from. If you are using this filter with a conduit, the idiom to use is:
1
2
auto input = new ZlibInput(myConduit.input));
input.read(myContent);

The optional windowBits parameter is the base two logarithm of the window size, and should be in the range 8-15, defaulting to 15 if not specified. Additionally, the windowBits parameter may be negative to indicate that zlib should omit the standard zlib header and trailer, with the window size being -windowBits.

Params:

streamcompressed input stream.
encodingstream encoding. Defaults to Encoding.Guess, which should be sufficient unless the stream was compressed with no encoding; in this case, you must manually specify Encoding.None.
windowBitsthe base two logarithm of the window size, and should be in the range 8-15, defaulting to 15 if not specified.
size_t read(void[] dst) [override] #
Decompresses data from the underlying conduit into a target array.
Returns the number of bytes stored into dst, which may be less than requested.
InputStream flush() [override] #
Clear any buffered content. No-op.
class ZlibOutput : OutputFilter #
This output filter can be used to perform compression of data into a zlib stream.
enum Level #
This enumeration represents several pre-defined compression levels.
Any integer between -1 and 9 inclusive may be used as a level, although the symbols in this enumeration should suffice for most use-cases.
Normal #
Default compression level. This is selected for a good compromise between speed and compression, and the exact compression level is determined by the underlying zlib library. Should be roughly equivalent to compression level 6.
None #
Do not perform compression. This will cause the stream to expand slightly to accommodate stream metadata.
Fast #
Minimal compression; the fastest level which performs at least some compression.
Best #
Maximal compression.
enum Encoding #
This enumeration allows you to specify what the encoding of the compressed stream should be.
Zlib #
Stream should use zlib encoding.
Gzip #
Stream should use gzip encoding.
None #
Stream should use no encoding.
this(OutputStream stream, Level level, Encoding encoding, int windowBits = WINDOWBITS_DEFAULT) #
this(OutputStream stream, Level level = Level.Normal) #
Constructs a new zlib compression filter. You need to pass in the stream that the compression filter will write to. If you are using this filter with a conduit, the idiom to use is:
1
2
auto output = new ZlibOutput(myConduit.output);
output.write(myContent);

The optional windowBits parameter is the base two logarithm of the window size, and should be in the range 8-15, defaulting to 15 if not specified. Additionally, the windowBits parameter may be negative to indicate that zlib should omit the standard zlib header and trailer, with the window size being -windowBits.

size_t write(void[] src) [override] #
Compresses the given data to the underlying conduit.
Returns the number of bytes from src that were compressed; write should always consume all data provided to it, although it may not be immediately written to the underlying output stream.
size_t written() #
This read-only property returns the number of compressed bytes that have been written to the underlying stream. Following a call to either close or commit, this will contain the total compressed size of the input data stream.
void close() [override] #
commit the output
void commit() #
Purge any buffered content. Calling this will implicitly end the zlib stream, so it should not be called until you are finished compressing data. Any calls to either write or commit after a compression filter has been committed will throw an exception.
class ZlibClosedException : IOException #
This exception is thrown if you attempt to perform a read, write or flush operation on a closed zlib filter stream. This can occur if the input stream has finished, or an output stream was flushed.
class ZlibException : IOException #
This exception is thrown when an error occurs in the underlying zlib library. Where possible, it will indicate both the name of the error, and any textural message zlib has provided.