开发者

How to unzip compressed files using C#?

How can I use C# to unzip files? I've found that I have to use third-part开发者_如何学Cy libraries. Is there any direct method?


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.


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


Are you looking for http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx ?


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.


.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.


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:

  • https://github.com/DinoChiesa/DotNetZip. Looks to be the original author's repo.
  • https://github.com/haf/DotNetZip.Semverd. This looks to be the currently maintained version. It's also packaged up an available via Nuget at https://www.nuget.org/packages/DotNetZip/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜