Decompress streams.
Imports System.IO
Imports System.IO.Compression
Module Module1
Sub Main()
Dim dirpath As String = "c:\reports"
Dim di As DirectoryInfo = New DirectoryInfo(dirpath)
For Each fi As FileInfo In di.GetFiles("*.gz")
Decompress(fi)
Next
End Sub
Private Sub Decompress(ByVal fi As FileInfo)
Using inFile As FileStream = fi.OpenRead()
Dim curFile As String = fi.FullName
Dim origName = curFile.Remove(curFile.Length - fi.Extension.Length)
Using outFile As FileStream = File.Create(origName)
Using Decompress As GZipStream = New GZipStream(inFile, CompressionMode.Decompress)
Dim buffer As Byte() = New Byte(4096) {}
Dim numRead As Integer
numRead = Decompress.Read(buffer, 0, buffer.Length)
Do While numRead <> 0
outFile.Write(buffer, 0, numRead)
numRead = Decompress.Read(buffer, 0, buffer.Length)
Loop
End Using
End Using
End Using
End Sub
End Module
Related examples in the same category