GZipStream Class
Imports System
Imports System.IO
Imports System.IO.Compression
Public Class GZipTest
Public Shared Function ReadAllBytesFromStream(stream As Stream, buffer() As Byte) As Integer
Dim offset As Integer = 0
Dim totalCount As Integer = 0
While True
Dim bytesRead As Integer = stream.Read(buffer, offset, 100)
If bytesRead = 0 Then
Exit While
End If
offset += bytesRead
totalCount += bytesRead
End While
Return totalCount
End Function
Public Shared Sub Main(ByVal args() As String)
Dim infile As FileStream
infile = New FileStream("c:\\", FileMode.Open, FileAccess.Read, FileShare.Read)
Dim buffer(infile.Length - 1) As Byte
Dim count As Integer = infile.Read(buffer, 0, buffer.Length)
infile.Close()
Dim ms As New MemoryStream()
Dim compressedzipStream As New GZipStream(ms, CompressionMode.Compress, True)
compressedzipStream.Write(buffer, 0, buffer.Length)
compressedzipStream.Close()
ms.Position = 0
Dim zipStream As New GZipStream(ms, CompressionMode.Decompress)
Dim decompressedBuffer(buffer.Length + 100) As Byte
Dim totalCount As Integer = GZipTest.ReadAllBytesFromStream(zipStream, decompressedBuffer)
zipStream.Close()
End Sub
End Class
Related examples in the same category