Skip to content
Andrew Lambert edited this page Jan 1, 2022 · 22 revisions

Method Signatures

 Shared Function Open(InputStream As Readable,   Encoding As Integer = zlib.Z_DETECT) As zlib.ZStream
 Shared Function Open(InputStream As FolderItem, Encoding As Integer = zlib.Z_DETECT) As zlib.ZStream

Parameters

Name Type Comment
InputStream Readable, FolderItem The file or stream to decompress from.
Encoding Integer Optional. The type of compression.

Return value

A new instance of ZStream, or Nil on error

Remarks

Opens a compressed file or readable stream for decompression.

Example

This example demonstrates how to use the ZStream.Open and ZStream.Create shared methods in concert with the built-in BinaryStream class to read and write a gzip-compressed text file on the user's desktop.

Dim outfile As FolderItem = SpecialFolder.Desktop.Child("hello.txt.gz")
Dim filestream As BinaryStream
Dim gzipstream As zlib.ZStream

' Create the file and then the compression stream
filestream = BinaryStream.Create(outfile)
gzipstream = zlib.ZStream.Create(filestream, zlib.Z_DEFAULT_COMPRESSION, zlib.GZIP_ENCODING)
For i As Integer = 0 To 9
  gzipstream.Write("This text will be compressed using gzip!")
Next
gzipstream.Close()
filestream.Close()

' Open the file and then the decompression stream
filestream = BinaryStream.Open(outfile)
gzipstream = zlib.ZStream.Open(filestream, zlib.GZIP_ENCODING)
Dim s As String
Do Until gzipstream.EOF
  s = gzipstream.Read(1024 * 64)
Loop
gzipstream.Close
filestream.Close

MsgBox(s)

See also

Entry-level points of interest denoted by "☜"



Clone this wiki locally