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); }
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.
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(); }
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