ZlibStream Constructor (stream, mode, level)

DotNetZip

Ionic Zip Library v1.9.1.6 ZlibStream Constructor (stream, mode, level)
ReferenceIonic.ZlibZlibStreamZlibStream(Stream, CompressionMode, CompressionLevel)
Create a ZlibStream using the specified CompressionMode and the specified CompressionLevel.
Declaration Syntax
C# Visual Basic Visual C++
public ZlibStream(
	Stream stream,
	CompressionMode mode,
	CompressionLevel level
)
Public Sub New ( _
	stream As Stream, _
	mode As CompressionMode, _
	level As CompressionLevel _
)
public:
ZlibStream(
	Stream^ stream, 
	CompressionMode mode, 
	CompressionLevel level
)
Parameters
stream (Stream)
The stream to be read or written while deflating or inflating.
mode (CompressionMode)
Indicates whether the ZlibStream will compress or decompress.
level (CompressionLevel)
A tuning knob to trade speed for effectiveness.
Remarks

When mode is CompressionMode.Decompress, the level parameter is ignored. The "captive" stream will be closed when the ZlibStream is closed.

Examples
This example uses a ZlibStream to compress data from 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,
                                                  CompressionLevel.BestCompression))
        {
            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, CompressionLevel.BestCompression)
            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)