ZlibStream Constructor (stream, mode)

DotNetZip

Ionic Zip Library v1.9.1.6 ZlibStream Constructor (stream, mode)
ReferenceIonic.ZlibZlibStreamZlibStream(Stream, CompressionMode)
Create a ZlibStream using the specified CompressionMode.
Declaration Syntax
C# Visual Basic Visual C++
public ZlibStream(
	Stream stream,
	CompressionMode mode
)
Public Sub New ( _
	stream As Stream, _
	mode As CompressionMode _
)
public:
ZlibStream(
	Stream^ stream, 
	CompressionMode mode
)
Parameters
stream (Stream)
The stream which will be read or written.
mode (CompressionMode)
Indicates whether the ZlibStream will compress or decompress.
Remarks

When mode is CompressionMode.Compress, the ZlibStream will use the default compression level. The "captive" stream will be closed when the ZlibStream is closed.

Examples
This example uses a ZlibStream to compress a file, and writes the compressed data to another file.
CopyC#
using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
{
    using (var raw = System.IO.File.Create(fileToCompress + ".zlib"))
    {
        using (Stream compressor = new ZlibStream(raw, CompressionMode.Compress))
        {
            byte[] buffer = new byte[WORKING_BUFFER_SIZE];
            int n;
            while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
            {
                compressor.Write(buffer, 0, n);
            }
        }
    }
}
CopyVB.NET
Using input As Stream = File.OpenRead(fileToCompress)
    Using raw As FileStream = File.Create(fileToCompress & ".zlib")
    Using compressor As Stream = New ZlibStream(raw, CompressionMode.Compress)
        Dim buffer As Byte() = New Byte(4096) {}
        Dim n As Integer = -1
        Do While (n <> 0)
            If (n > 0) Then
                compressor.Write(buffer, 0, n)
            End If
            n = input.Read(buffer, 0, buffer.Length)
        Loop
    End Using
    End Using
End Using

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)