FAQ - icsharpcode/SharpZipLib GitHub Wiki

Frequently Asked Questions for the Sharp Zip compression library

Back to SharpZipLib - Main Page

FAQs

What formats does SharpZipLib support?

Sharpzip supports Zip files using both stored and deflate compression methods and also supports old (PKZIP 2.0) style and AES encryption, tar with GNU long filename extensions, gzip, zlib and raw deflate, as well as BZip2.

Zip64 is supported while Deflate64 is not yet supported. AES is supported for encryption and decryption except for the ZipInputStream class (use ZipFile with an input stream until this is completed).

Where can I find the documentation?

The documentation generated from the source code is available at https://icsharpcode.github.io/SharpZipLib/help/api/

Can I use SharpZipLib in my commercial application?

Yes you can, SharpZipLib is now MIT licensed.

How do I compress/decompress files in memory?

Use a memory stream when creating the Zip stream!

   MemoryStream outputMemStream = new MemoryStream(); 
   using (ZipOutputStream zipOutput = new ZipOutputStream(outputMemStream)) {
   // Use zipOutput stream as normal
   ...

You can get the resulting data with memory stream methods ToArray or GetBuffer.

ToArray is the cleaner and easiest to use correctly with the penalty of duplicating allocated memory. GetBuffer returns a raw buffer raw and so you need to account for the true length yourself.

See the framework class library help for more information.

Windows XP explorer doesnt show my files, whats wrong?

To allow the windows built in Zip handling to show details in a Zip file the entries must use relative paths. A relative path should start with a name like example.txt or subdir/a.dat.

The other cause of problems is Zip64 extensions which allow a very large number of files and very large files to be compressed. However XP doesnt understand Zip64 and will complain or show incorrect file sizes.

Within the library when creating entries try to ensure that the size of entries is set before they are added to the archive. This ensures the correct format is used. If you cant do this then a fallback is the UseZip64 property which can be used to turn this off. The downside is that if a large file is encountered then archive creation will fail.

One reason explorer can block access which has nothing to do with the contents of files is that untrusted files can be blocked.
The Attachment Manager that is included in Microsoft Windows XP Service Pack 2 (SP2) can block files that are deemed unsafe.

You can open a blocked file from a known source if you want to. To open a blocked file, follow these steps:

  1. Right-click the blocked file, and then click Properties.

  2. In the General tab, click Unblock.

You can read about the attachment manager in this Microsoft knowledge base article.

Some people have reported problems with network drives so try shifting the file to a local drive if nothing else works.

How can I create a Zip file without folders?

Remove the path portion of the filename used to create a ZipEntry before it is added to a ZipOutputStream

ZipEntry entry = new ZipEntry(Path.GetFileName(fullPath));

My decompressed files are invalid whats wrong?

When reading from streams you should keep reading until the end of the stream has been reached. Do not assume that because you provide a buffer big enough that it will be filled in a single read. When a read returns 0 the end of the stream has been reached.

StreamUtils.Copy(sourceStream, destinationStream, new byte[2048]);

How do I process a large file without using lots of memory?

Using code similar to that shown below will do the job.

StreamUtils.Copy(sourceStream, destinationStream, new byte[2048]);

I get an exception Wrong Local Header Signature what is wrong?

The exception is thrown when trying to read a local file entry header and the expected signature isnt found. The file may actually be corrupt but check the version of SharpZip you are using as many fixes have been made in this area.

How to use ZLib style compression?

Use InflaterInputStream and DeflaterOutputStream classes. The classes Inflater and Deflater are not recommended as they are very low level.

I am using a French (Japanese, Greek, ...) version of windows how do I create Zip files with accents or non ASCII characters?

This should happen automatically in most cases. The key is to set the appropriate code page via the property ZipStrings.DefaultCodePage before compressing or decompressing any files. For many European countries code page 850 will work fine.

Can I create TAR entries with long filenames?

Yes, the library supports GNU extensions that allow long filenames. This happens automatically when a long name is detected.

How do I add an empty folder to a Zip file?

Create an entry whose name has a trailing slash ('/') character and add it to the Zip file.

   using (ZipOutputStream zipStream = new ZipOutputStream(File.Create("demo.zip"))) {
      ZipEntry zipEntry = new ZipEntry("emptyFolder/");
      zipStream.PutNextEntry(zipEntry);
      ... 
   }

Can I do Zip64 with SharpZipLib?

Yes SharpZipLib handles Zip64 extensions. NOTE that XP's built in compression does not however handle this currently.

When I try to run my program I am getting a file load exception "The located assembly's manifest definition with the name 'ICSharpCode.SharpZipLib' does not match the assembly reference" whats that all about?{BR} The version of sharp zip found doesnt match the version your program was compiled against. The quick fix is to recompile with the latest version of the library. Alternatively you can alter the configuration for the application, see the microsoft help on how to do this.

I get a header checksum exception thrown when trying to inflate data. Any tips?

Rather than new InflaterInputStream(stream);

try new InflaterInputStream(stream, new Inflater(true));

The first form does gzip the second does deflate.

Some handy non FAQ information (Zip file formats)

Info zips application note(older but has lots of extra information)

PKWare Zip application note

SharpZipLib main page