views:

1773

answers:

8

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

+24  A: 

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
You don't need this .NET has build in functionality: see gzipstream class.
Tony Lambert
gzipstream is not anything nearby zip-functionality.
BeowulfOF
I think you getting too caught up with the files... gzip is a general compression format.
Tony Lambert
Right, gzip is a compression format, but not for file-containers. And gzip is not zip.
BeowulfOF
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
Unfortunately. SharpZipLib is currently unmaintained and somewhat buggy.
Laurynas Biveinis
+7  A: 

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
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
+1, SDK is public domain too, thats sounds real good to me.
Tuminoid
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
+7  A: 

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

Tony Lambert
how does the compression ratio compare to 7-Zip ?
Pure.Krome
Its the same as gZIP.
Tony Lambert
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.
BeowulfOF
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?
Tony Lambert
7-ZIP Is not a library.
Tony Lambert
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
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.
BeowulfOF
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
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
+6  A: 

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

Mark Maslar
Does not expand some of the files that SharpZipLib does.
Sergey Aldoukhov
which files does it not expand?
Cheeso
A: 

you can also check out the J# redist. It re-implements java.util.zip. Article

jwmiller5
A: 

Give a look here if you want 7-zip with C#. This was a question in an other post at SO. This might help you.

Daok
+13  A: 

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

Cheeso
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
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
A: 

Xceed Zip for .NET for a pro commercial solution that supports all the latest Winzip 12 Zip format extensions such as the LZMA algorithm (from 7-Zip!), UTF-8 file headers, etc.

Xceed Zip for .NET

Odi - Xceed