Skip to content
Andrew Lambert edited this page Nov 26, 2022 · 20 revisions

zlib.Deflater

Class Declaration

 Protected Class Deflater

Remarks

This class represents a compression stream. If you don't need low-level control over the compression process then the easier to use ZStream class should be preferred.

Methods

Properties

Example

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.

Entry-level points of interest denoted by "☜"



Clone this wiki locally