Decompress gz file

  • Thread starter Thread starter DavidC
  • Start date Start date
D

DavidC

We have a file downloaded from another company in the format filename.csv.gz
that apparently was compressed with GZipStream. I would like to create a
class that decompresses it (which it does with WinZip) from an asp.net page.
I found the code below in msdn that is suppose to work. However, the line
that reads

Decompress.CopyTo(outFile)

gives an error that CopyTo is not a method in GZipStream. Can anyone help me
resolve this? It seems like a clean process if I can get it to work. Thanks.

Private Sub Decompress(ByVal fi As FileInfo)
' Get the stream of the source file.
Using inFile As FileStream = fi.OpenRead()
' Get orignial file extension, for example "doc" from
report.doc.gz.
Dim curFile As String = fi.FullName
Dim origName = curFile.Remove(curFile.Length -
fi.Extension.Length)

' Create the decompressed file.
Using outFile As FileStream = File.Create(origName)
Using Decompress As GZipStream = New GZipStream(inFile, _
CompressionMode.Decompress)

' Copy the decompression stream
' into the output file.
Decompress.CopyTo(outFile)

Console.WriteLine("Decompressed: {0}", fi.Name)

End Using
End Using
End Using
End Sub
 
Back
Top