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

zlib.ZStream

Class Declaration

 Protected Class ZStream
 Implements Readable,Writeable

Remarks

A ZStream is a compressed data stream. Depending on the initialization options it can read or write DEFLATE-compressed streams, with or without zlib or gzip style headers/footers.

Instances of ZStream can be created directly from a BinaryStream or MemoryBlock by passing it to the Constructor() method, or from other kinds of objects through the Open() and Create() shared methods.

A ZStream has a reference to a Writeable object to which all compressed output is ultimately written; this is the "output stream". Another reference is held to a Readable object which is the ultimate source for all compressed input; this is the "input stream". Typically, when compressing you only specify the output stream and when decompressing only the input stream.

This class implements the Readable and Writeable class interfaces.

Methods

Properties

Shared Methods

Example

This example creates an in-memory compression stream by calling Constructor(MemoryBlock), and writes some data that will be compressed using GZip at maximum compression:

  Dim output As New MemoryBlock(0)
  Dim compressor As New zlib.ZStream(output, zlib.Z_BEST_COMPRESSION, zlib.GZIP_ENCODING)
  compressor.Write("Hello, world!")
  compressor.Close

This example reads raw compressed bytes from a BinaryStream that also has sections of uncompressed bytes. BufferedReading is set to False because we need the ZStream to read exactly the number of bytes we tell it to.

  Dim binstream As BinaryStream = BinaryStream.Open(GetOpenFolderItem(""))
  Dim decompressor As zlib.ZStream = zlib.ZStream.Open(binstream, zlib.RAW_ENCODING)
  decompressor.BufferedReading = False
  
  Dim uncompressedpart1, uncompressedpart2, compressedpart1, compressedpart2 As String
  ' read raw bytes
  uncompressedpart1 = binstream.Read(LengthOfUncompressedPart1)
  ' read compressed bytes
  compressedpart1 = decompressor.Read(LengthOfCompressedPart1)
  ' read some more raw bytes
  uncompressedpart2 = binstream.Read(LengthOfUncompressedPart2)
  ' read some more compressed bytes
  compressedpart2 = decompressor.Read(LengthOfCompressedPart2)
  'etc.

Entry-level points of interest denoted by "☜"



Clone this wiki locally