27

Does anyone know of a good open-source zipping library for .NET?

fARcRY
  • 2,338
  • 6
  • 24
  • 40
  • May have been reworded "I need to generate zip archives using .net. But .Net lacks zip archive support. How can we overcome this issue?". But since fx 4.5 this looks fixed through [System.IO.Compression.ZipArchive](https://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive(v=vs.110).aspx). – Frédéric May 15 '15 at 10:19

5 Answers5

35

SharpZipLib

Regarding the comments and other posts about the internal gzip implementation, they are not the same! GZip does not create the header required for archiving; it is only useful for "zipping" one file or stream.

Proper zip archives contain a header that list all compressed files and where in the compressed data they come and therefore you need something that makes a header. That means SharpZipLib, one of the many commercial versions or using something external with .NET bindings like 7zip.

Just on the offchance somebody wants to say this: "But I see .gz files in Linux all the time!" - they're just single files and .tar.gz is no exception - tar is the archive file. The .gz is that archive compressed.

Oli
  • 235,628
  • 64
  • 220
  • 299
  • You don't need this .NET has build in functionality: see gzipstream class. – AnthonyLambert Dec 17 '08 at 12:47
  • gzipstream is not anything nearby zip-functionality. – Oliver Friedrich Dec 17 '08 at 13:00
  • I think you getting too caught up with the files... gzip is a general compression format. – AnthonyLambert Dec 17 '08 at 13:16
  • 5
    Right, gzip is a compression format, but not for file-containers. And gzip is not zip. – Oliver Friedrich Dec 18 '08 at 09:50
  • I had this exact question, and this solution was very fast to implement. The ZipFast class lets me do most of what I need in a single line of code. Perfect. – Jeffrey Apr 29 '09 at 14:45
  • 3
    Unfortunately. SharpZipLib is currently unmaintained and somewhat buggy. – Laurynas Biveinis Oct 08 '09 at 17:40
  • Yeah, SharpZipLib is unmaintained and buggy. Last release in June 2010. It sometimes has issues with zip files produced by 7zip, ioniczip, etc, even though the zip files are completely fine. We use it for a component at my work and have had to resort to fixing the source and building locally, which is not that big of a deal, but not something you want to have to get into if you are looking for a turnkey zip library. – aggieNick02 Jan 11 '13 at 17:23
  • Just got bit by a bug. Using it in TFS Build automation - have 7 services with 3 configurations = so 21 MSI's to produce a zip of 113MB - and it randomly "hangs"... – fuzzbone Dec 02 '13 at 16:51
25

Couple comments.

  1. Don't use the J# runtime. J# has been discontinued by Microsoft. Future support is questionable. Also, the entire J# runtime is a big nut to swallow when all you want is ZIP support.
  2. The GzipStream in System.IO.Compression, part of the .NET base class library since .NET 2.0, provides a stream interface for IETF RFC-1952 compression. It is ok for compression, though the compression ratio is not optimal and it will significantly expand data that has been previously compressed. This bug was reported to Microsoft, but it's apparently been closed. There is also a DeflateStream which is similar, but for RFC 1951. There's a common misconception that GZipStream does zip files. Not true. Neither of these two do zip files.
  3. There's System.IO.Packaging.ZipPackage. It works, but is designed and intended primarily for packaging of MS Office 2007 (.docx, .xslx, and .pptx) files. It's unwieldy for zip files and doesn't support lots of ZIP features, like encryption.
  4. If you want a flexible way to create and read zip files in .NET you need a 3rd party library, currently.

DotNetZip is a good 3rd party option. Free, open source, actively maintained, simple to use, small, good feature set. It is shipped as a single assembly - it is fully managed code. Works on Compact Framework as well as on the regular .NET Framework. The pre-req is .NET 2.0.

DotNetZip also includes a ZLIB library, with classes like {Zlib,GZip,Deflate}Stream. They are comparable to those built-in to .NET, but they include the ability to set Compression Levels, and at higher levels they compress much more effectively than the built-in classes. The ZlibStream does RFC 1950 compression.

DotNetZip does ZIP64, passwords, AES encryption, streams, SFX, and Unicode. Everyone who uses it says it is much simpler to use than SharpZipLib. There's a good help file (.chm) and lots of code examples.

DNZ CHM

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • Do you know, can DotNetZip be included in an open source project? I heard that Microsoft Public License cannot be used together with a GPL. – Zenya Oct 19 '10 at 07:36
  • First, I'm not an IP attorney or an expert on software licenses and their mutual compatibility. However, I am confident that I can answer your first question affirmatively: DotNetZip can be used in an open source project. There is a second, implied question in your comment: Can a library licensed under the MS-PL be used together with code or a library licensed under the GPL? That is a different question entirely, and I won't attempt to answer it. I'm not sure, but there may be an assumption on your part that "open source implies GPL". This is not a valid assumption. – Cheeso Oct 24 '10 at 14:44
  • 2
    DotNetZip now suffers the same troubles than SharpZipLib: no more maintained (no new release since 2011), with [serious bug](http://dotnetzip.codeplex.com/workitem/14087). But since .Net 4.5 we now have [System.IO.Compression.ZipArchive](https://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive(v=vs.110).aspx) class: I have yet to test it. – Frédéric May 15 '15 at 09:47
12

The DotNet Zip Library (Ionic.Zip.dll) is very easy to use. I feel that it's easier to implement than SharpZip.

http://www.codeplex.com/DotNetZip

Cheeso
  • 189,189
  • 101
  • 473
  • 713
Mark Maslar
  • 1,121
  • 4
  • 16
  • 28
9

Try checking out 7-zip. It's open source and my fav zip program. very kewl. takes advantage of multi cores also.

The .NET SDK is available here.

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
  • Dude - 7 zip IS a zipping program. It's also open source .. so that means it's .NET right? ==> C# source code for LZMA compression and decompression – Pure.Krome Dec 17 '08 at 12:36
  • 2
    +1, SDK is public domain too, thats sounds real good to me. – Tuminoid Dec 17 '08 at 12:42
  • 1
    A word of caution: the (safe) C# implementation of 7-zip is very, very much slower than the unmanaged library, something like 10x (private impression, didn't benchmark since the difference was so large). – Anton Tykhyy Jun 30 '09 at 16:19
9

**** But guys .NET Already supports open source zip....****

http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx

This is compatible with the GZIP libraries. I used this to compress c# data and decompress across the network in a C++ application. Works fine.

Tony

AnthonyLambert
  • 8,768
  • 4
  • 37
  • 72
  • how does the compression ratio compare to 7-Zip ? – Pure.Krome Dec 17 '08 at 12:50
  • the system.io.compression namespace is not completly opened, the useful stuff is inside the microsoft.internal namespace. In system.io.compression is only the part usefull for creating small zipped files, like the new office files, not real zip files. – Oliver Friedrich Dec 17 '08 at 13:00
  • He didn't say he wanted to produce files.... He may just want to zip information to persist in one of many ways, might he? – AnthonyLambert Dec 17 '08 at 13:02
  • What do you mean not real .zip files? a .zip file is a .zip file, regardless of what you put in it. The .NET libraries will create .zip file you need containing anything you want to put in it. – Russ Dec 17 '08 at 15:12
  • 1
    Sorry, not real zip-files means no zip-file container, but data, that is packet by a deflate algorythm. Look at the functions in system.io.compression you will clearly see, that the purpose is another than microsoft.internal.zip -> what is what sharpziblib covers. – Oliver Friedrich Dec 17 '08 at 17:49
  • 2
    NO, Russ - the .NET libraries in System.IO.Compression do not create or read ZIP files. I agree with Beowulf. You can try System.IO.Packaging, but that will leave you frustrated. a third party library is best. – Cheeso Mar 07 '09 at 08:36
  • The compression ratio delivered by the .NET BCL DeflateStream and GZipStream is NOT as good as what is available in zlib. If you don't believe me, benchmark it yourself : grab the zlib libraries in http://DotNetZip.codeplex.com and test it. (zlib is in some cases 30% better) – Cheeso Mar 07 '09 at 08:37