Ionic Zip Library v1.9.1.6
DeflateStream Constructor (stream, mode)
Reference ► Ionic.Zlib ► DeflateStream ► DeflateStream(Stream, CompressionMode)
Create a DeflateStream using the specified CompressionMode.
Declaration Syntax
C# | Visual Basic | Visual C++ |
public DeflateStream( Stream stream, CompressionMode mode )
Public Sub New ( _ stream As Stream, _ mode As CompressionMode _ )
public: DeflateStream( Stream^ stream, CompressionMode mode )
Parameters
- stream (Stream)
- The stream which will be read or written.
- mode (CompressionMode)
- Indicates whether the DeflateStream will compress or decompress.
Remarks
When mode is CompressionMode.Compress, the DeflateStream will use
the default compression level. 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)) { 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 & ".deflated") Using compressor As Stream = New DeflateStream(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