DeflateStream Constructor (stream, mode, level)

DotNetZip

Ionic Zip Library v1.9.1.6 DeflateStream Constructor (stream, mode, level)
ReferenceIonic.ZlibDeflateStreamDeflateStream(Stream, CompressionMode, CompressionLevel)
Create a DeflateStream using the specified CompressionMode and the specified CompressionLevel.
Declaration Syntax
C# Visual Basic Visual C++
public DeflateStream(
	Stream stream,
	CompressionMode mode,
	CompressionLevel level
)
Public Sub New ( _
	stream As Stream, _
	mode As CompressionMode, _
	level As CompressionLevel _
)
public:
DeflateStream(
	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 DeflateStream 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 DeflateStream is closed.

Examples
This example uses a DeflateStream 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 + ".deflated"))
    {
        using (Stream compressor = new DeflateStream(raw,
                                                     CompressionMode.Compress,
                                                     CompressionLevel.BestCompression))
        {
            byte[] buffer = new byte[WORKING_BUFFER_SIZE];
            int n= -1;
            while (n != 0)
            {
                if (n > 0)
                    compressor.Write(buffer, 0, n);
                n= input.Read(buffer, 0, buffer.Length);
            }
        }
    }
}
CopyVB.NET
Using input As Stream = File.OpenRead(fileToCompress)
    Using raw As FileStream = File.Create(fileToCompress & ".deflated")
        Using compressor As Stream = New DeflateStream(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)