473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 2172

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: William | last post by:
I am using DB2 8.2 on RH Linux 8.0. I just compiled db2uext2.c but failed to archive the log files, did anybody fix this problem before? TIA db2diag.log 2005-06-12-12.39.52.305630-240...
6
by: JezB | last post by:
From a windows application, I want to provide an "archive" facility which will scan a specific directory and put specific files into some single "Archive file", a bit like a zip-file I guess, but...
5
by: Sahil Malik [MVP] | last post by:
Okay I installed the LINQ preview on Beta2, and anything I write gives me this error now. The documentation over here - http://msdn.microsoft.com/vs2005/currentreadme/default.aspx aptly tells...
0
by: Ian Lane .enizin.net> | last post by:
Hello, I am having a very strange issue regarding our macintosh users running IE. For some reason some users running IE on the Mac are getting an invalid viewstate exception when first coming to...
11
by: MrNobody | last post by:
I need to zip up an 8Gb file using C# - do you know of any freeware libraries I can use to accomplish this? I guess it needs to be Zip64 to support such file sizes. I tried something called...
2
by: Sugan | last post by:
Hi All, I have a peculiar kind of issue after converting VC and VB code from Visual studio 6.0 to Visual Studio 2005. We have the business logic in the VC code which uses the ATL framework...
0
by: =?Utf-8?B?Y2hveWsx?= | last post by:
Hi, How can I know if the stream is a gzipped stream or not without .gz extension? GZipStream does not provide Seek method...
6
by: =?Utf-8?B?QkRSaWNoYXJkc29u?= | last post by:
Hi, I have been using the new GZipStream classes, and have been experiencing problems when attemping to decompress files, which from experience, seem to be failing when the original file size...
2
by: =?Utf-8?B?TWFydGluIE1hZHJlemE=?= | last post by:
Hi, i've got problems with CryptoStream and GZipStream. Someone tried that? Or got any idea why this wont work? i tried every combination, first i used CryptoStream, after that GZipStream. Or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.