Export (0) Print
Expand All

DeflateStream.Write Method

Writes compressed bytes to the underlying stream from the specified byte array.

Namespace:  System.IO.Compression
Assembly:  System (in System.dll)

'Declaration
Public Overrides Sub Write ( _
	array As Byte(), _
	offset As Integer, _
	count As Integer _
)

Parameters

array
Type: System.Byte()

The buffer that contains the data to compress.

offset
Type: System.Int32

The byte offset in array from which the bytes will be read.

count
Type: System.Int32

The maximum number of bytes to write.

The following example shows how to compress and decompress bytes by using the Read and Write methods.

Imports System.IO
Imports System.IO.Compression
Imports System.Text

Module Module1

    Sub Main()
        Dim uniEncode As UnicodeEncoding = New UnicodeEncoding()

        Dim bytesToCompress = uniEncode.GetBytes("example text to compress and decompress")
        Console.WriteLine("starting with: " + uniEncode.GetString(bytesToCompress))

        Using fileToCompress As FileStream = File.Create("examplefile.gz")
            Using compressionStream As DeflateStream = New DeflateStream(fileToCompress, CompressionMode.Compress)
                compressionStream.Write(bytesToCompress, 0, bytesToCompress.Length)
            End Using 
        End Using 

        Dim decompressedBytes(bytesToCompress.Length - 1) As Byte 
        Using fileToDecompress As FileStream = File.Open("examplefile.gz", FileMode.Open)
            Using decompressionStream As DeflateStream = New DeflateStream(fileToDecompress, CompressionMode.Decompress)
                decompressionStream.Read(decompressedBytes, 0, bytesToCompress.Length)
            End Using 
        End Using

        Console.WriteLine("ending with: " + uniEncode.GetString(decompressedBytes))
    End Sub 
End Module

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1
Show:
© 2015 Microsoft