views:

1585

answers:

7

Is there a built-in zip library in .NET 3.5?

If not, what are the popular open source .net zip libraries.

+3  A: 

Try System.IO.Compression.DeflateStream.

Inferis
No, DeflateStream doesn't do ZIP files. Just FYI, neither does the built-in GZipStream. Also, both these streams can exhibit anomalous compression behavior with previously-compressed or incompressible data. They can actually increase the size of the data. you've been warned!
Cheeso
+21  A: 

Open source: #ZipLib

I believe that the classes in the System.IO.Compression namespace are fine for compressing/decompressing a single stream of data, but there's nothing built into the framework to cope with actual zip files.

EDIT: As noted in Ants' answer, there's System.IO.Packaging.ZipPackage but it certainly looks like that's really designed for use in WPF, and wouldn't be terribly convenient to use for general zip file handling. Worth looking into though. I wasn't aware of it before though... definitely worth investigating.

Jon Skeet
true. #ZipLib works good.
Inferis
isn't c# 4.0 going to natively support this? i thought I had read that somewhere. But I have used ZipLib before with success.
Jon Erickson
I don't know whether .NET 4.0 will have support for this - I wouldn't be surprised. It's still a way off though :)
Jon Skeet
I found that the SharpZipLib API can be more complicated than it needs to be. Also it is much more than zip - tar, bzip, and i don't know what else. Maybe "too much" if you just want zip. Last, are some things missing? like progress events? AES? maybe these are coming. I'm not aware.
Cheeso
+5  A: 

7Zip will help and its available in multiple languages

Oscar Cabrero
+6  A: 

Check out System.IO.Packaging.ZipPackage class.

Ants
I had no idea this existed.
Inferis
This requires things to be in a package format which requires an XML file inside the zip file that defines the layout. It's not a general purpose zip library.
Jeff Moser
+4  A: 

There is no built-in library. There are open-source options.

DotNetZip is one. Simple, easy to use. It has good features: AES Encryption, regular encryption, streams, ZIP64, file comments, Unicode, progress events, more. And it's free and open source.

Here's some sample code.

    // extract all Photoshop files larger than 100mb
    using (ZipFile zip1 = ZipFile.Read(ZipFileName))
    {
        var LargePhotoShopFiles = zip1.SelectEntries("name = *.psd  and size > 100mb");
        foreach (ZipEntry e in LargePhotoShopFiles)
        {
            if (e.UsesEncryption)
                e.ExtractWithPassword("unpackDirectory", "VerySecret!");
            else 
                e.Extract("unpackDirectory");
        }
    }
Cheeso
I'm very impressed with this library. Using it with great success now - thanks for the heads up.
Guy
+1  A: 

I will be second to recommend http://www.7-zip.org/sdk.html LZMA SDK, but it's not ZIP.

  1. It's in public domain
  2. It's FAST on decompression
  3. It has fully managed implementation
  4. It's much better compressing than ZIP/RAR
  5. It has very small footprint
  6. It can work as a stream
Mash