Keyoti RapidSpell Desktop .NET API Docs
GZipStream Constructor (stream, mode)
APIKeyoti.RapidSpell.CompressionGZipStreamGZipStream(Stream, CompressionMode)
Keyoti RapidSpell Desktop .NET
Create a GZipStream using the specified CompressionMode.
Declaration Syntax
C#C#Visual BasicVisual BasicVisual C++Visual C++F#F#
public GZipStream(
	Stream stream,
	CompressionMode mode
)
public GZipStream(
	Stream stream,
	CompressionMode mode
)
Public Sub New ( 
	stream As Stream,
	mode As CompressionMode
)
Public Sub New ( 
	stream As Stream,
	mode As CompressionMode
)
public:
GZipStream(
	Stream^ stream, 
	CompressionMode mode
)
public:
GZipStream(
	Stream^ stream, 
	CompressionMode mode
)
new : 
        stream : Stream * 
        mode : CompressionMode -> GZipStream
new : 
        stream : Stream * 
        mode : CompressionMode -> GZipStream
Parameters
stream (Stream)
The stream which will be read or written.
mode (CompressionMode)
Indicates whether the GZipStream will compress or decompress.
Remarks

When mode is CompressionMode.Compress, the GZipStream will use the default compression level.

As noted in the class documentation, the CompressionMode (Compress or Decompress) also establishes the "direction" of the stream. A GZipStream with CompressionMode.Compress works only through Write(). A GZipStream with CompressionMode.Decompress works only through Read().

Examples
This example shows how to use a GZipStream to compress data.
 Copy imageCopy
using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
{
    using (var raw = System.IO.File.Create(outputFile))
    {
        using (Stream compressor = new GZipStream(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);
            }
        }
    }
}
Visual Basic Copy imageCopy
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 GZipStream(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
Examples
This example shows how to use a GZipStream to uncompress a file.
 Copy imageCopy
private void GunZipFile(string filename)
{
    if (!filename.EndsWith(".gz))
        throw new ArgumentException("filename");
    var DecompressedFile = filename.Substring(0,filename.Length-3);
    byte[] working = new byte[WORKING_BUFFER_SIZE];
    int n= 1;
    using (System.IO.Stream input = System.IO.File.OpenRead(filename))
    {
        using (Stream decompressor= new Keyoti.RapidSpell.Compression.GZipStream(input, CompressionMode.Decompress, true))
        {
            using (var output = System.IO.File.Create(DecompressedFile))
            {
                while (n !=0)
                {
                    n= decompressor.Read(working, 0, working.Length);
                    if (n > 0)
                    {
                        output.Write(working, 0, n);
                    }
                }
            }
        }
    }
}
Visual Basic Copy imageCopy
Private Sub GunZipFile(ByVal filename as String)
    If Not (filename.EndsWith(".gz)) Then
        Throw New ArgumentException("filename")
    End If
    Dim DecompressedFile as String = filename.Substring(0,filename.Length-3)
    Dim working(WORKING_BUFFER_SIZE) as Byte
    Dim n As Integer = 1
    Using input As Stream = File.OpenRead(filename)
        Using decompressor As Stream = new Keyoti.RapidSpell.Compression.GZipStream(input, CompressionMode.Decompress, True)
            Using output As Stream = File.Create(UncompressedFile)
                Do
                    n= decompressor.Read(working, 0, working.Length)
                    If n > 0 Then
                        output.Write(working, 0, n)
                    End IF
                Loop While (n  > 0)
            End Using
        End Using
    End Using
End Sub

Assembly: Keyoti.RapidSpell.NET4 (Module: Keyoti.RapidSpell.NET4.dll) Version: 6.2.21.412