L
Lloyd Spencer
Hi,
I have been unable to find and am therefore trying to write code to do the
following:
get a GZip file from the internet
unzip it
use it as a text file
The problem I am having is that the output from the GZipStream is the same
as the input, ie: I don't end up with more or different bytes. If anyone has
any suggestions for what I am doing wrong, they would be most welcome. This
appears to be relatively new in .net and I can't find out much about it.
Apologies in advance if this is an inappropriate forum, etc. Any direction
at all would be great.
Code follows:
Public Function ReadFtpZip(ByVal url As String) As Byte()
' first get the data from the ftp site
Dim objRequest As WebRequest = FtpWebRequest.Create(url)
objRequest.Method = WebRequestMethods.Ftp.DownloadFile
Dim objResponse As FtpWebResponse = objRequest.GetResponse()
Dim objStreamReader As New
StreamReader(objResponse.GetResponseStream())
' next define the raw data stream and write the ftp stream to it
Dim objStream As New MemoryStream
Dim objWriter = New StreamWriter(objStream)
objWriter.AutoFlush = True
objWriter.Write(objStreamReader.ReadToEnd)
' now we define the zipstream mystery object
Dim zipStream As New GZipStream(objStream, CompressionMode.Decompress)
zipStream.BaseStream.Position = 0
' now we have to read through this stream and output it to an answer
stream somehow
Dim theByte As Integer = zipStream.BaseStream.ReadByte()
Dim outputStream As New MemoryStream
While theByte <> -1
outputStream.WriteByte(CType(theByte, Byte))
theByte = zipStream.BaseStream.ReadByte()
End While
Return outputStream.ToArray()
End Function
I have been unable to find and am therefore trying to write code to do the
following:
get a GZip file from the internet
unzip it
use it as a text file
The problem I am having is that the output from the GZipStream is the same
as the input, ie: I don't end up with more or different bytes. If anyone has
any suggestions for what I am doing wrong, they would be most welcome. This
appears to be relatively new in .net and I can't find out much about it.
Apologies in advance if this is an inappropriate forum, etc. Any direction
at all would be great.
Code follows:
Public Function ReadFtpZip(ByVal url As String) As Byte()
' first get the data from the ftp site
Dim objRequest As WebRequest = FtpWebRequest.Create(url)
objRequest.Method = WebRequestMethods.Ftp.DownloadFile
Dim objResponse As FtpWebResponse = objRequest.GetResponse()
Dim objStreamReader As New
StreamReader(objResponse.GetResponseStream())
' next define the raw data stream and write the ftp stream to it
Dim objStream As New MemoryStream
Dim objWriter = New StreamWriter(objStream)
objWriter.AutoFlush = True
objWriter.Write(objStreamReader.ReadToEnd)
' now we define the zipstream mystery object
Dim zipStream As New GZipStream(objStream, CompressionMode.Decompress)
zipStream.BaseStream.Position = 0
' now we have to read through this stream and output it to an answer
stream somehow
Dim theByte As Integer = zipStream.BaseStream.ReadByte()
Dim outputStream As New MemoryStream
While theByte <> -1
outputStream.WriteByte(CType(theByte, Byte))
theByte = zipStream.BaseStream.ReadByte()
End While
Return outputStream.ToArray()
End Function