DeflateStream Class : DeflateStream « File Directory « VB.Net

DeflateStream Class


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

Public Class DeflateTest
   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 DeflateCompressDecompress(filename As String)
        Dim infile As FileStream
         infile = New FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)
            Dim buffer(infile.Length - 1) As Byte
            Dim count As Integer = infile.Read(buffer, 0, buffer.Length)
         If count <> buffer.Length Then
         End If
         Dim ms As New MemoryStream()
         Dim compressedzipStream As New DeflateStream(ms, CompressionMode.Compress, True)
         compressedzipStream.Write(buffer, 0, buffer.Length)
         ms.Position = 0
         Dim zipStream As New DeflateStream(ms, CompressionMode.Decompress)
         Dim decompressedBuffer(buffer.Length + 100) As Byte
         Dim totalCount As Integer = DeflateTest.ReadAllBytesFromStream(zipStream, decompressedBuffer)
        Catch e As Exception
        End Try
   End Sub 
    Public Shared Sub Main(ByVal args() As String)
    End Sub 'Main
End Class 'DeflateTest 


Related examples in the same category

1.DeflateStream Class is for compressing and decompressing streams using the Deflate algorithm.