An array of bytes containing the decompressed data. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + nb bytes read) replaced by the bytes read from the current source.
The zero-based byte offset in buffer at which to begin storing the data read from the current stream.
The maximum number of bytes to be read from the current stream.
An array of bytes containing the decompressed data. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + nb bytes read) replaced by the bytes read from the current source.
offset
The zero-based byte offset in buffer at which to begin storing the data read from the current stream.
count
The maximum number of bytes to be read from the current stream.
Return Value
The total number of bytes read into the buffer. This may be less than the number of bytes
requested if that many bytes are not currently available, or zero (0) if the end of the stream
has been reached.
Example
The following example demonstrates how to read compressed data from a MemoryStream and
decompress it to a FileStream using the GZipCompressedStream class.
Imports System.IO
Imports Xceed.Compression
Imports Xceed.Compression.Formats
' If you do not want the inner stream to be closed by the GZipCompressedStream
' then set the GZipCompressedStream's Transient property to true.
'
' The compressed data was compressed using the Compress example
Dim sourceStream = New MemoryStream(compressedData)
Dim gzip AsNew GZipCompressedStream(sourceStream)
Dim destinationStream AsNew FileStream("d:\data.txt", FileMode.OpenOrCreate)
' 32K at a time.
Dim buffer(32768) AsByteDim bytesRead AsInteger = 0
' Loop until we have nothing more to read from the source stream
Do
bytesRead = gzip.Read(buffer, 0, buffer.Length)
If bytesRead > 0 Then
destinationStream.Write(buffer, 0, bytesRead)
EndIfLoopUntil bytesRead = 0
' Close the destination stream and the GZipCompressedStream.
'
' Because the GZipCompressedStream will automatically close the source
' memory stream, there is no need to call Close once we are done with the stream.
destinationStream.Close()
gzip.Close()
using System.IO;
using Xceed.Compression;
using Xceed.Compression.Formats;
// Because the GZipCompressedStream will automatically close the source
// memory stream, there is no need to declare the memory stream within a using
// statement or to call Close once we are done with the stream.
//
// If you do not want the inner stream to be closed by the GZipCompressedStream
// then set the GZipCompressedStream's Transient property to true.
//
// The compressed data was compressed using the Compress example
MemoryStream sourceStream = new MemoryStream( compressedData );
using( GZipCompressedStream gzip = new GZipCompressedStream( sourceStream ) )
{
using( FileStream destinationStream = new FileStream( @"d:\data.txt", FileMode.OpenOrCreate ) )
{
// 32K at a time.
byte[] buffer = newbyte[ 32768 ];
int bytesRead = 0;
// Loop until we have nothing more to read from the source stream.
while( ( bytesRead = gzip.Read( buffer, 0, buffer.Length ) ) > 0 )
{
destinationStream.Write( buffer, 0, bytesRead );
}
}
}
Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2