471,831 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,831 software developers and data experts.

Invalid archive when using GZipStream

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?

thanks,

Craig Buchanan

<code>
Public Sub CompressFile(ByVal sourceFile As String, ByVal destinationFile As
String)
' 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
Try
' Read the bytes from the source file into a byte array
sourceStream = New FileStream(sourceFile, FileMode.Open, FileAccess.Read,
FileShare.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,
FileAccess.Write)
' 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)
Finally
' Make sure we allways close all streams
If Not (sourceStream Is Nothing) Then
sourceStream.Close()
End If
If Not (compressedStream Is Nothing) Then
compressedStream.Close()
End If
If Not (destinationStream Is Nothing) Then
destinationStream.Close()
End If
End Try
End Sub
</code>
May 23 '06 #1
0 2099

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by William | last post: by
6 posts views Thread by JezB | last post: by
5 posts views Thread by Sahil Malik [MVP] | last post: by
reply views Thread by Ian Lane .enizin.net> | last post: by
11 posts views Thread by MrNobody | last post: by
reply views Thread by =?Utf-8?B?Y2hveWsx?= | last post: by
6 posts views Thread by =?Utf-8?B?QkRSaWNoYXJkc29u?= | last post: by
2 posts views Thread by =?Utf-8?B?TWFydGluIE1hZHJlemE=?= | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.