CompressionMethod Property

DotNetZip

Ionic Zip Library v1.9.1.6 CompressionMethod Property
ReferenceIonic.ZipZipEntryCompressionMethod
The compression method employed for this ZipEntry.
Declaration Syntax
C# Visual Basic Visual C++
public CompressionMethod CompressionMethod { get; set; }
Public Property CompressionMethod As CompressionMethod
	Get
	Set
public:
property CompressionMethod CompressionMethod {
	CompressionMethod get ();
	void set (CompressionMethod value);
}
Remarks

The Zip specification allows a variety of compression methods. This library supports just two: 0x08 = Deflate. 0x00 = Store (no compression), for reading or writing.

When reading an entry from an existing zipfile, the value you retrieve here indicates the compression method used on the entry by the original creator of the zip. When writing a zipfile, you can specify either 0x08 (Deflate) or 0x00 (None). If you try setting something else, you will get an exception.

You may wish to set CompressionMethod to CompressionMethod.None (0) when zipping already-compressed data like a jpg, png, or mp3 file. This can save time and cpu cycles.

When setting this property on a ZipEntry that is read from an existing zip file, calling ZipFile.Save() will cause the new CompressionMethod to be used on the entry in the newly saved zip file.

Setting this property may have the side effect of modifying the CompressionLevel property. If you set the CompressionMethod to a value other than None, and CompressionLevel is previously set to None, then CompressionLevel will be set to Default.

Examples
In this example, the first entry added to the zip archive uses the default behavior - compression is used where it makes sense. The second entry, the MP3 file, is added to the archive without being compressed.
CopyC#
using (ZipFile zip = new ZipFile(ZipFileToCreate))
{
  ZipEntry e1= zip.AddFile(@"notes\Readme.txt");
  ZipEntry e2= zip.AddFile(@"music\StopThisTrain.mp3");
  e2.CompressionMethod = CompressionMethod.None;
  zip.Save();
}
CopyVB.NET
Using zip As New ZipFile(ZipFileToCreate)
  zip.AddFile("notes\Readme.txt")
  Dim e2 as ZipEntry = zip.AddFile("music\StopThisTrain.mp3")
  e2.CompressionMethod = CompressionMethod.None
  zip.Save
End Using
See Also
CompressionMethod

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)