Xceed.Compression.Silverlight.v6.6 Assembly > Xceed.Compression Namespace > CompressedStream Class : Read Method |
'Declaration Public Overrides Function Read( _ ByVal buffer() As Byte, _ ByVal offset As Integer, _ ByVal count As Integer _ ) As Integer
'Usage Dim instance As CompressedStream Dim buffer() As Byte Dim offset As Integer Dim count As Integer Dim value As Integer value = instance.Read(buffer, offset, count)
The CompressedStream object reads and decompresses data from the inner stream into a private buffer, and uses this buffer to satisfy Read requests. If a such a request cannot be satisfied, more data is read and decompressed from the inner stream.
When Read returns a positive value, it means that there is more uncompressed data available in the CompressedStream buffer, but the end of the inner stream could have already been reached.
When this method returns 0, it really means that all of the inner stream's data has been read and decompressed.
If the reading process to decompress the byte array has already begun, CanWrite will always return false.
Imports System.IO Imports Xceed.Compression ' If you do not want the inner stream to be closed by the CompressedStream ' then set the CompressedStream's Transient property to true. ' ' The compressed data was compressed using the Compress example Dim sourceStream = New MemoryStream( compressedData ) Dim compStream As New CompressedStream( sourceStream ) Dim destinationStream As New FileStream("d:\data.txt", FileMode.OpenOrCreate) ' 32K at at time. Dim buffer(32768) As Byte Dim bytesRead As Integer = 0 ' Loop until we have nothing more to read from the source stream Do bytesRead = compStream.Read(buffer, 0, buffer.Length) If bytesRead > 0 Then destinationStream.Write(buffer, 0, bytesRead) End If Loop Until bytesRead = 0 ' Close the destination stream and the CompressedStream. ' ' Because the CompressedStream will automatically close the source ' memory stream, there is no need to call Close once we are done with the stream. destinationStream.Close() compStream.Close()
using System.IO; using Xceed.Compression; // Because the CompressedStream 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 CompressedStream // Then Set the CompressedStream's Transient property to true. // // The compressed Data was compressed using the Compress example MemoryStream sourceStream = New MemoryStream( compressedData ); using( CompressedStream compStream = New CompressedStream( sourceStream ) ) { using( FileStream destinationStream = New FileStream( @"d:\data.txt", FileMode.OpenOrCreate ) ) { // 32K at at time. Byte[] buffer = New Byte[ 32768 ]; int bytesRead = 0; // Loop Until we have Nothing more To Read from the source stream. While( ( bytesRead = compStream.Read( buffer, 0, buffer.Length ) ) > 0 ) { destinationStream.Write( buffer, 0, bytesRead ); } } }
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
CompressedStream Class
CompressedStream Members
Base Implementation in Read