-
-
Notifications
You must be signed in to change notification settings - Fork 3
zlib.Deflater
zlib.Deflater
Protected Class Deflater
This class performs compression of a stream. If you don't need low-level control over the compression process then the easier to use ZStream class should be preferred.
- Avail_In
- Avail_Out
- CompressBound
- Constructor
- Deflate
- LastError
- Prime
- Reset
- SetHeader
- Total_In
- Total_Out
- Tune
This example gzips a string:
Dim def As New zlib.Deflater(zlib.Z_BEST_COMPRESSION, zlib.Z_DEFAULT_STRATEGY, zlib.GZIP_ENCODING, zlib.DEFAULT_MEM_LVL)
Dim compressed As String = def.Deflate("Hello, world!", zlib.Z_FINISH)
This example uses a very short input string, so short that compressing happens in one call to Deflate
. However, Deflate
does not necessarily consume compressed data immediately. The "sliding window" determines the size of the compression buffer, and the size of the compression buffer determines how many uncompressed bytes have to be consumed in order to emit one or more compressed bytes.
In the above example we are passing Z_FINISH
to Deflate
, which tells the decompressor that no more data is coming and it should emit everything it has left in the buffer. You must always do this when you're finished compressing otherwise the uncompressed bytes still in the buffer will be lost. Refer to the zlib documentation on the various ways you can flush the compression buffer short of Z_FINISH
.
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2014-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.