Xceed.Compression.Silverlight.v6.6 Assembly > Xceed.Compression Namespace > CompressedStream Class : Write Method |
'Declaration Public Overrides Sub Write( _ ByVal buffer() As Byte, _ ByVal offset As Integer, _ ByVal count As Integer _ )
'Usage Dim instance As CompressedStream Dim buffer() As Byte Dim offset As Integer Dim count As Integer instance.Write(buffer, offset, count)
Imports System.IO Imports Xceed.Compression Dim sourceStream As New FileStream("d:\data.txt", FileMode.Open) ' If you do not want the inner stream to be closed by the CompressedStream ' then set the CompressedStream's Transient property to true. Dim destinationStream As New MemoryStream() Dim compStream As New CompressedStream( destinationStream ) '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 = sourceStream.Read(buffer, 0, buffer.Length) If bytesRead > 0 Then compStream.Write(buffer, 0, bytesRead) End If Loop Until bytesRead = 0 ' Close the source stream and the CompressedStream. ' ' Because the CompressedStream will automatically close the destination ' memory stream, there is no need to call Close once we are done with the stream. sourceStream.Close() compStream.Close() ' To get access to the MemoryStream's compressed data, you can use ' Dim compressedData() As Byte = destinationStream.ToArray() ' ToArray() works even when the memory stream is closed.
using System.IO; using Xceed.Compression; using( FileStream sourceStream = New FileStream( @"d:\data.txt", FileMode.Open ) ) { // Because the CompressedStream will automatically Close the destination // 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. MemoryStream destinationStream = New MemoryStream(); using( CompressedStream compStream = New CompressedStream( destinationStream ) ) { // 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 = sourceStream.Read( buffer, 0, buffer.Length ) ) > 0 ) { compStream.Write( buffer, 0, bytesRead ); } } // To Get access To the MemoryStream's compressed data, you can use // Byte[] compressedData = destinationStream.ToArray(); // ToArray() works even When the memory stream Is closed. }
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 Write