By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

Invalid archive when using GZipStream

P: n/a
when i try to open a file that has been compressed with GZipStream (source
from microsoft's 101 Samples for Visual Studio 2005), i get an "invalid
archive" message from winzip, zipgenius and xp's compressed folder app.
using DeflateStream resulted in the same error.

am i missing something simple?


Craig Buchanan

Public Sub CompressFile(ByVal sourceFile As String, ByVal destinationFile As
' make sure the source file is there
If File.Exists(sourceFile) = False Then
Throw New FileNotFoundException
End If
' Create the streams and byte arrays needed
Dim buffer As Byte() = Nothing
Dim sourceStream As FileStream = Nothing
Dim destinationStream As FileStream = Nothing
Dim compressedStream As GZipStream = Nothing
'Dim compressedStream As DeflateStream = Nothing
' Read the bytes from the source file into a byte array
sourceStream = New FileStream(sourceFile, FileMode.Open, FileAccess.Read,
' Read the source stream values into the buffer
buffer = New Byte(sourceStream.Length) {}
Dim checkCounter As Integer = sourceStream.Read(buffer, 0, buffer.Length)
' Open the FileStream to write to
destinationStream = New FileStream(destinationFile, FileMode.OpenOrCreate,
' Create a compression stream pointing to the destiantion stream
compressedStream = New GZipStream(destinationStream,
CompressionMode.Compress, True)
'compressedStream = New DeflateStream(destinationStream,
CompressionMode.Compress, True)
'Now write the compressed data to the destination file
compressedStream.Write(buffer, 0, buffer.Length)
Catch ex As ApplicationException
MessageBox.Show(ex.Message, "An Error occured during compression",
MessageBoxButtons.OK, MessageBoxIcon.Error)
' Make sure we allways close all streams
If Not (sourceStream Is Nothing) Then
End If
If Not (compressedStream Is Nothing) Then
End If
If Not (destinationStream Is Nothing) Then
End If
End Try
End Sub
May 23 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.