-
-
Notifications
You must be signed in to change notification settings - Fork 3
zlib.ZStream.Create
Andrew Lambert edited this page Nov 26, 2022
·
24 revisions
Shared Function Create(OutputStream As Writeable, CompressionLevel As Integer = zlib.Z_DEFAULT_COMPRESSION, Encoding As Integer = zlib.DEFLATE_ENCODING) As zlib.ZStream
Shared Function Create(OutputStream As FolderItem, CompressionLevel As Integer = zlib.Z_DEFAULT_COMPRESSION, Overwrite As Boolean = False, Encoding As Integer = zlib.DEFLATE_ENCODING) As zlib.ZStream
Name | Type | Comment |
---|---|---|
OutputStream |
Writeable , FolderItem
|
Compressed output will be written to this object |
CompressionLevel | Integer | Optional. The compression level for the stream. Valid levels are 1 (fast) to 9 (best) |
Overwrite | Boolean | Optional. If True , the OutputStream FolderItem is overwritten if it exists. |
Encoding | Integer | Optional. The type of compression. |
A new instance of ZStream.
Creates a new deflate stream for writing. Compressed data will be written to the OutputStream
object. On error an exception will be raised.
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)
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.