Use GZipStream to decompress winzip file

G

Guest

Hi there,

I am trying to use GZipStream class to decompress winzip files in .NET 2.0
C# and getting the following error message:

The magic number in GZip header is not correct. Make sure you are passing in
a GZip stream.

The zip file I am using for testing was compressed by winzip and nothing
special there. I guess if you use GZipStream to compress and decompress data
there will be no problom. But is it possible to use to decompress the file
that is compressed by winzip?

Thanks,
Mike
 
P

Peter Duniho

VancouverMike wrote:
[...]
The zip file I am using for testing was compressed by winzip and nothing
special there. I guess if you use GZipStream to compress and decompress data
there will be no problom. But is it possible to use to decompress the file
that is compressed by winzip?

Not unless the WinZip file is specifically the Gzip format. While
related, they aren't actually the same. One particular difference is
that Gzip compresses a single stream of data, while WinZip .zip files
can contain multiple files and folders. Of course, there are other
differences as well; the main thing is that they aren't the same.

Pete
 
G

Guest

Thanks Pete!

If this is the case, is there any class/way in .NET Framework 2.0 I can use
to decompress the winzip files without using the third party utilities?

Mike

Peter Duniho said:
VancouverMike wrote:
[...]
The zip file I am using for testing was compressed by winzip and nothing
special there. I guess if you use GZipStream to compress and decompress data
there will be no problom. But is it possible to use to decompress the file
that is compressed by winzip?

Not unless the WinZip file is specifically the Gzip format. While
related, they aren't actually the same. One particular difference is
that Gzip compresses a single stream of data, while WinZip .zip files
can contain multiple files and folders. Of course, there are other
differences as well; the main thing is that they aren't the same.

Pete
 
P

Peter Duniho

VancouverMike said:
Thanks Pete!

If this is the case, is there any class/way in .NET Framework 2.0 I can use
to decompress the winzip files without using the third party utilities?

There is a sort of hack that involves using the Windows shell to
decompress zip files. There's no direct API in .NET, but Windows
Explorer does support creating and decompression .zip files, and you can
get at that functionality through some form of automation of the shell.

I don't recall the specifics, but Google can probably help you find
them. I'm pretty sure I saw one implementation on codeproject.com.

Pete
 
J

John Mott

The J# library can actually read and write zip files, although you have to
pull in a lot of Java types to use it.

I've been very happy with the C# SharpZipLib, which is free and seems to
work well. There are samples in the download but I'm thinking of putting
some up so they will be on the web.

http://www.icsharpcode.net/OpenSource/SharpZipLib/


john


VancouverMike said:
Thanks Pete!

If this is the case, is there any class/way in .NET Framework 2.0 I can
use
to decompress the winzip files without using the third party utilities?

Mike

Peter Duniho said:
VancouverMike wrote:
[...]
The zip file I am using for testing was compressed by winzip and
nothing
special there. I guess if you use GZipStream to compress and decompress
data
there will be no problom. But is it possible to use to decompress the
file
that is compressed by winzip?

Not unless the WinZip file is specifically the Gzip format. While
related, they aren't actually the same. One particular difference is
that Gzip compresses a single stream of data, while WinZip .zip files
can contain multiple files and folders. Of course, there are other
differences as well; the main thing is that they aren't the same.

Pete
 
J

Jesse Houwing

* VancouverMike wrote, On 30-7-2007 18:22:
Hi there,

I am trying to use GZipStream class to decompress winzip files in .NET 2.0
C# and getting the following error message:

The magic number in GZip header is not correct. Make sure you are passing in
a GZip stream.

The zip file I am using for testing was compressed by winzip and nothing
special there. I guess if you use GZipStream to compress and decompress data
there will be no problom. But is it possible to use to decompress the file
that is compressed by winzip?

Thanks,
Mike

have a look at this free component:

http://www.icsharpcode.net/OpenSource/SharpZipLib/

it does all you need :)

Jesse
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top