Xceed .NET Libraries Documentation
The ZipItemLocalHeader class
Welcome to Xceed .NET, .NET Standard and Xamarin Libraries! > Basic Concepts > Zip and streaming capabilities > Real-Time Zip Classes > The ZipItemLocalHeader class

The ZipItemLocalHeader class represents the local header of an item in a Zip archive. When creating a Zip archive, you must use the WriteItemLocalHeader method to write each ZipItemLocalHeader to the archive. When reading a Zip archive, a ZipItemLocalHeader is read using the ReadItemLocalHeader method.

For details on how to use this class when creating or reading a Zip archive, see The ZipWriter class and The ZipReader class.

The ZipItemLocalHeader class provides six properties which will be described below. Minimally, a filename is passed to the class constructor, which is used to set the FileName property. Another version of the class constructor allows you to set the compression level / method, while a third additionally lets you set the encryption method / password.

Compression Level and Method

Use the CompressionLevel and CompressionMethod properties to set the level and method of compression before an item is added to a Zip archive, or to consult these values when reading a Zip archive. The following table lists the compression methods available. When the compression method is not specified in the ZipItemLocalHeader constructor, the default value of Deflated is used.

When EncryptionMethod is set to WinZipAes, the compression level is hidden and is not available in  CompressionLevel.
Compression Method Description
Stored No compression is applied.

Note: This compression method is not supported by the ZipWriter class and will result in an exception if encountered. This compression method is only partially supported by the ZipReader class .
Deflated

Deflate algorithm. Standard algorithm used by the PKZip 2.04g format.

Note: This is the default value used when the compression method is not specified in the the ZipItemLocalHeader constructor.

Deflated64 Also know as Enhanced Deflate.  

Deflate64 is a variation of the Deflate algorithm that uses a 64K sliding window rather than a 32K window in order to compress a sequence of bits. Deflate64 takes longer to compress data than Deflate; however, it provides better compression.

BZip2

A BWT-based block-sorting algorithm used in zip files created with WinZip 11.0 and up. An excellent alternative to Deflate and Deflate64 when speed can be traded off.

BWT

The raw BWT block-sorting algorithm. Produces smaller compressed output than the BZip2 method, but is not compatible with WinZip. It is compatible with zip files created using the BWT compression method offered by Xceed Zip Compression Library ActiveX.

PPMd

A PPM-based predictor algorithm used in zip files created with Winzip 11.0 and up. In our tests, especially with text files and XML files, the PPMd method generally produced the smallest compressed output.

Xceed recommends that the PPMd compression method be selected when dealing with text files, XML files, and other files with high redundancy, as this is where the PPMd algorithm is able to create smaller files than the other compression methods.

The following table lists the compression levels available. When the compression level is not specified in the ZipItemLocalHeader constructor, the default value of Normal is used.

Compression Level Description
None No compression is applied. CompressionLevel.None is not supported by this product and will result in an exception being thrown if encountered.
Lowest Minimum compression. Takes the least amount of time to compress data.
Normal Normal compression. Best balance between the time it takes to compress data and the compression ratio achieved.

Note: This is the default value used when the compression level is not specified in the the ZipItemLocalHeader constructor.
Highest Maximum compression. Best compression ratio that the compression algorithm is capable of producing. Compared to the Normal compression level, this level significantly increases compression time for only slightly smaller compressed data. It is recommended to use this setting only when you really need to achieve the smallest possible files and when compression time is not important.

The compression level only applies to the Deflated, Deflated64, LZMA, and PPMd compression methods. It does not apply to the BZip2 or BWT compression methods.

Encryption Method and Password

Use the EncryptionMethod and EncryptionPassword properties to encrypt and password protect files in a Zip archive, or to consult these values when reading a Zip archive. The following table lists the encryption methods available. When the encryption method is not specified in the ZipItemLocalHeader constructor, the default value of Compatible is used; however, if EncryptionPassword is not set, this value is ignored (no encryption will occur).

Encryption Method Description
Compatible The traditional ZIP encryption. This is a weak encryption method.

Note: This is the default value used when the encryption method is not specified in the the ZipItemLocalHeader constructor.
WinZipAes The WinZip AES encryption method. This is a strong encryption method. When  EncryptionMethod is set to this value, the compression level is hidden in the resulting archive and is therefore not available in CompressionLevel.

Examples

Example 1: Creating a ZipItemLocalHeader

The following examples show how to create a ZipItemLocalHeader object with each of the three available class constructors and illustrates the parameters available.

//Sets the filename of the item in the Zip archive. Default values are used for

//compression method / level and for encryption method / password (which

//is ""). 

ZipItemLocalHeader zipItemLocalHeader1 = new ZipItemLocalHeader(file.Name);

//Sets the filename and compression method / level. Encryption method /

//password (which is "").

ZipItemLocalHeader zipItemLocalHeader1 = new ZipItemLocalHeader(file.Name, 

  Xceed.Compression.CompressionMethod.Deflated, 

  Xceed.Compression.CompressionLevel.Highest);

//Sets the filename, compression method / level, and encryption method /

//password.

ZipItemLocalHeader zipItemLocalHeader1 = new ZipItemLocalHeader(file.Name,

  Xceed.Compression.CompressionMethod.Deflated, 

  Xceed.Compression.CompressionLevel.Highest,

  Xceed.Zip.EncryptionMethod.WinZipAes, "password");
'Sets the filename of the item in the Zip archive. Default values are used for

'compression method / level and for encryption method / password (which

'is "").

Dim zipItemLocalHeader1 As New ZipItemLocalHeader(file.Name)

'Sets the filename and compression method / level. Encryption method /

'password (which is "").

Dim zipItemLocalHeader1 As New ZipItemLocalHeader(file.Name,

  Xceed.Compression.CompressionMethod.Deflated,

  Xceed.Compression.CompressionLevel.Highest)

'Sets the filename, compression method / level, and encryption method /

'password.

Dim zipItemLocalHeader1 As New ZipItemLocalHeader(file.Name,

  Xceed.Compression.CompressionMethod.Deflated,

  Xceed.Compression.CompressionLevel.Highest,

  Xceed.Zip.EncryptionMethod.WinZipAes, "password")