DeflateStream Constructor (stream, mode, level, leaveOpen)

DotNetZip

Ionic Zip Library v1.9.1.6 DeflateStream Constructor (stream, mode, level, leaveOpen)
ReferenceIonic.ZlibDeflateStreamDeflateStream(Stream, CompressionMode, CompressionLevel, Boolean)
Create a DeflateStream using the specified CompressionMode and the specified CompressionLevel, and explicitly specify whether the stream should be left open after Deflation or Inflation.
Declaration Syntax
C# Visual Basic Visual C++
public DeflateStream(
	Stream stream,
	CompressionMode mode,
	CompressionLevel level,
	bool leaveOpen
)
Public Sub New ( _
	stream As Stream, _
	mode As CompressionMode, _
	level As CompressionLevel, _
	leaveOpen As Boolean _
)
public:
DeflateStream(
	Stream^ stream, 
	CompressionMode mode, 
	CompressionLevel level, 
	bool leaveOpen
)
Parameters
stream (Stream)
The stream which will be read or written.
mode (CompressionMode)
Indicates whether the DeflateStream will compress or decompress.
level (CompressionLevel)
A tuning knob to trade speed for effectiveness.
leaveOpen (Boolean)
true if the application would like the stream to remain open after inflation/deflation.
Remarks

When mode is CompressionMode.Decompress, the level parameter is ignored.

This constructor allows the application to request that the captive stream remain open after the deflation or inflation occurs. By default, after Close() is called on the stream, the captive stream is also closed. In some cases this is not desired, for example if the stream is a MemoryStream that will be re-read after compression. Specify true for the leaveOpen parameter to leave the stream open.

Examples
This example shows how to use a DeflateStream to compress data from a file, and store the compressed data into another file.
CopyC#
using (var output = System.IO.File.Create(fileToCompress + ".deflated"))
{
    using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
    {
        using (Stream compressor = new DeflateStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, true))
        {
            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);
            }
        }
    }
    // can write additional data to the output stream here
}
CopyVB.NET
Using output As FileStream = File.Create(fileToCompress & ".deflated")
    Using input As Stream = File.OpenRead(fileToCompress)
        Using compressor As Stream = New DeflateStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, True)
            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
    ' can write additional data to the output stream here.
End Using

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