Skip to content

zlib.ZStream.Constructor

Andrew Lambert edited this page Nov 28, 2022 · 22 revisions

zlib.ZStream.Constructor

Method Signatures

 ' General purpose constructors
 Sub Constructor(Source As MemoryBlock,  CompressionLevel As Integer = zlib.Z_DEFAULT_COMPRESSION, Encoding As Integer = zlib.Z_DETECT)
 Sub Constructor(Source As BinaryStream, CompressionLevel As Integer = zlib.Z_DEFAULT_COMPRESSION, Encoding As Integer = zlib.Z_DETECT)

 ' Constructors available to subclasses
 Protected Sub Constructor(Engine As zlib.Deflater, Destination As Writeable)
 Protected Sub Constructor(Engine As zlib.Inflater, Source As Readable)

Parameters

Constructor(MemoryBlock or BinaryStream, Integer, Integer)

Name Type Comment
Source MemoryBlock, BinaryStream A zero-length MemoryBlock or BinaryStream to use for output, or a >0 length MemoryBlock or BinaryStream to use for input
CompressionLevel Integer Optional. The compression level for the output. Valid levels are 1(fast) to 9(best)
Encoding Integer Optional. The type of compression. One of DEFLATE_ENCODING, GZIP_ENCODING, or RAW_ENCODING. Other values are possible for special cases; refer to the zlib documentation on the "windowBits" parameter for details.

Protected Constructor(zlib.Deflater, Writeable)

Name Type Comment
Engine Deflater An instance of Deflater that is ready to receive uncompressed input.
Destination Writeable The stream to which compressed output will be written.

Protected Constructor(zlib.Inflater, Readable)

Name Type Comment
Engine Inflater An instance of Inflater that is ready to receive compressed input.
Source Readable The stream from which compressed input is to be read.

Remarks

Constructs a ZStream from the Source MemoryBlock or BinaryStream. If the Source as a MemoryBlock has a Size of zero, or as a BinaryStream its Length is equal to its Position, then compressed data will be written to the Source; otherwise, the Source will be used as input to be decompressed.

Protected constructors

The protected constructors are for advanced users with special cases. If that's not you then you probably want the ZStream.Create and ZStream.Open shared methods instead.

To use the protected constructors create a custom subclass of ZStream and use the Super keyword (i.e. Super.Constructor()).

Example

This example creates a ZStream from a zero-length MemoryBlock and writes(compresses) as string into it, then it creates a second ZStream for reading the compressed string:

  Dim data As New MemoryBlock(0)
  Dim z As New zlib.ZStream(data)
  z.Write("Hello, world!")
  z.Close
  z = New zlib.ZStream(data)
  MsgBox(z.ReadAll)

Entry-level points of interest denoted by "☜"



Clone this wiki locally