Adham
Adham

Reputation: 64904

How to unzip compressed files using C#?

How can I use C# to unzip files? I've found that I have to use third-party libraries. Is there any direct method?

Upvotes: 2

Views: 13199

Answers (6)

Nicholas Carey
Nicholas Carey

Reputation: 74345

For zip files, DotNetZip works great. Just one assembly is required for zip file support.

For gzip files, you can use the streams in the System.IO.Compression namespace, or DotNetZip. Note that if you have *.tar.gz or *.tgz files, you'll need something that speaks tar(1) or tar(5) as well.

For zlib compressed data, DotNetZip is your friend again. zlib uses the Deflate algorithm. I'm not sure if zlib6 and System.IO.Compression.DeflateStream are compatable, though.

There are other libraries that support these compression formats, but many of them, I believe, are wrappers around non-managed code. Whether that's a good or bad thing depends on your requirements.

DotNetZip is pure managed code. My tests show that it runs at about the same speed as the Info-Zip's open-source zip/unzip implementations. The resulting compressed files aren't byte-identical, but they are compatible and have approximately the same compression ratios.


Edited To Note: DotNetZip used to live at Codeplex. Codeplex has been shut down. The old archive is still available at Codeplex. It looks like the code has migrated to Github:


Upvotes: 0

Denise Skidmore
Denise Skidmore

Reputation: 2416

.NET 4.5 has a more useful ZipPackage class

http://msdn.microsoft.com/en-us/library/system.io.packaging.zippackage.aspx

It is still not real easy to use, the sample code in the class documentation is quite long.

Upvotes: 0

Ed Bayiates
Ed Bayiates

Reputation: 11230

I've had great luck with the free Iconic Zip from Codeplex. It zips and unzips very quickly, works well and is small in size. It also works with Mono.

Upvotes: 1

JAiro
JAiro

Reputation: 6009

You could use the tool of the framework to zip and then to unzip

sinxe .NET 1.x you there are a lot of compession libraries out on the net, some are free some are commercial. A great free library is #Zip, or the creator of the free C# IDE, #develop.

.NET Framework 2.0 has introduced GZipStream and DeflateStream classes for compression and decompression of streams. Here are links on MSDN:

http://msdn2.microsoft.com/en-us/library/system.io.compression.gzipstream(VS.80).aspx

http://msdn2.microsoft.com/en-US/library/system.io.compression.deflatestream(VS.80).aspx

Upvotes: 2

Darin Dimitrov
Darin Dimitrov

Reputation: 1039348

The System.IO.Packaging namespace contains some compression classes such as ZipPackage but they are by no means as simple as using a third party libraries. I strongly recommend you to consider a third party library.

Upvotes: 3

Related Questions