ParallelDeflateOutputStream Constructor (stream)

DotNetZip

Ionic Zip Library v1.9.1.6 ParallelDeflateOutputStream Constructor (stream)
ReferenceIonic.ZlibParallelDeflateOutputStreamParallelDeflateOutputStream(Stream)
Create a ParallelDeflateOutputStream.
Declaration Syntax
C# Visual Basic Visual C++
public ParallelDeflateOutputStream(
	Stream stream
)
Public Sub New ( _
	stream As Stream _
)
public:
ParallelDeflateOutputStream(
	Stream^ stream
)
Parameters
stream (Stream)
The stream to which compressed data will be written.
Remarks

This stream compresses data written into it via the DEFLATE algorithm (see RFC 1951), and writes out the compressed byte stream.

The instance will use the default compression level, the default buffer sizes and the default number of threads and buffers per thread.

This class is similar to DeflateStream, except that this implementation uses an approach that employs multiple worker threads to perform the DEFLATE. On a multi-cpu or multi-core computer, the performance of this class can be significantly higher than the single-threaded DeflateStream, particularly for larger streams. How large? Anything over 10mb is a good candidate for parallel compression.

Examples
This example shows how to use a ParallelDeflateOutputStream to compress data. It reads a file, compresses it, and writes the compressed data to a second, output file.
CopyC#
byte[] buffer = new byte[WORKING_BUFFER_SIZE];
int n= -1;
String outputFile = fileToCompress + ".compressed";
using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
{
    using (var raw = System.IO.File.Create(outputFile))
    {
        using (Stream compressor = new ParallelDeflateOutputStream(raw))
        {
            while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
            {
                compressor.Write(buffer, 0, n);
            }
        }
    }
}
CopyVB.NET
Dim buffer As Byte() = New Byte(4096) {}
Dim n As Integer = -1
Dim outputFile As String = (fileToCompress & ".compressed")
Using input As Stream = File.OpenRead(fileToCompress)
    Using raw As FileStream = File.Create(outputFile)
        Using compressor As Stream = New ParallelDeflateOutputStream(raw)
            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)