473,592 Members | 2,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?


Craig Buchanan

Public Sub CompressFile(By Val sourceFile As String, ByVal destinationFile As
' make sure the source file is there
If File.Exists(sou rceFile) = False Then
Throw New FileNotFoundExc eption
End If
' Create the streams and byte arrays needed
Dim buffer As Byte() = Nothing
Dim sourceStream As FileStream = Nothing
Dim destinationStre am As FileStream = Nothing
Dim compressedStrea m As GZipStream = Nothing
'Dim compressedStrea m As DeflateStream = Nothing
' Read the bytes from the source file into a byte array
sourceStream = New FileStream(sour ceFile, FileMode.Open, FileAccess.Read ,
' Read the source stream values into the buffer
buffer = New Byte(sourceStre am.Length) {}
Dim checkCounter As Integer = sourceStream.Re ad(buffer, 0, buffer.Length)
' Open the FileStream to write to
destinationStre am = New FileStream(dest inationFile, FileMode.OpenOr Create,
FileAccess.Writ e)
' Create a compression stream pointing to the destiantion stream
compressedStrea m = New GZipStream(dest inationStream,
CompressionMode .Compress, True)
'compressedStre am = New DeflateStream(d estinationStrea m,
CompressionMode .Compress, True)
'Now write the compressed data to the destination file
compressedStrea m.Write(buffer, 0, buffer.Length)
Catch ex As ApplicationExce ption
MessageBox.Show (ex.Message, "An Error occured during compression",
MessageBoxButto ns.OK, MessageBoxIcon. Error)
' Make sure we allways close all streams
If Not (sourceStream Is Nothing) Then
sourceStream.Cl ose()
End If
If Not (compressedStre am Is Nothing) Then
compressedStrea m.Close()
End If
If Not (destinationStr eam Is Nothing) Then
destinationStre am.Close()
End If
End Try
End Sub
May 23 '06 #1
0 2185

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

Similar topics

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- I3534G369 LEVEL: Error PID : 3300 TID : 8192 PROC : db2logmgr (SAMPLE) INSTANCE: db2prd NODE : 000
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 more windows standard. Then I want to provide a function "Import from Archive" which will accept the name of such an archive file, and be able to extract the files into some (other) directory (though normally it will be imported on a different...
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 me -- Also, an exception gets thrown in some cases System.InvalidProgramException: Common Language Runtime detected an invalid program
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 our site. When first time users come to the site they are redirected to a select location page where they need to select a country so we can show them proper pricing. However, users on the Mac seem to have issues during the redirect back to...
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 sharpziplib but it doesn't support >2Gb files - they are working on it however but I cannot wait...
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 and implements a COM server. VB code gives the GUI part of the project, For reporting custom errors like invalid login, we use AtlReportError method to report error from the VC code side.
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...
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 exceeds something like 64 MB. For example, when I attempt to decompress a text file of size 1.18 MB to its original size of 106 MB, I receive the following error message: System.IO.IOException: Insufficient system resources exist to complete the
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 first i create a file with GZipStream and crypt that file. But become back the orginal is impossible... I hope anyone got an idea how this could work.
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.