Class ZipEntry
This class represents an entry in a zip archive. This can be a file
or a directory
ZipFile and ZipInputStream will give you instances of this class as
information about the members in an archive. ZipOutputStream
uses an instance of this class when creating an entry in a Zip file.
Author of the original java version : Jochen Hoenicke
Inheritance
Inherited Members
Namespace: ICSharpCode.SharpZipLib.Zip
Assembly: ICSharpCode.SharpZipLib.dll
Syntax
public class ZipEntry
Constructors
| Improve this Doc View SourceZipEntry(ZipEntry)
Creates a deep copy of the given zip entry.
Declaration
[Obsolete("Use Clone instead")]
public ZipEntry(ZipEntry entry)
Parameters
Type | Name | Description |
---|---|---|
ZipEntry | entry | The entry to copy. |
ZipEntry(String)
Creates a zip entry with the given name.
Declaration
public ZipEntry(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name for this entry. Can include directory components. The convention for names is 'unix' style paths with relative names only. There are with no device names and path elements are separated by '/' characters. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The name passed is null |
Properties
| Improve this Doc View SourceAESKeySize
For AES encrypted files returns or sets the number of bits of encryption (128, 192 or 256). When setting, only 0 (off), 128 or 256 is supported.
Declaration
public int AESKeySize { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
CanDecompress
Get a value indicating whether this entry can be decompressed by the library.
Declaration
public bool CanDecompress { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
This is based on the Version and whether the compression method is supported.
CentralHeaderRequiresZip64
Get a value indicating whether the central directory entry requires Zip64 extensions to be stored.
Declaration
public bool CentralHeaderRequiresZip64 { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Comment
Gets/Sets the entry comment.
Declaration
public string Comment { get; set; }
Property Value
Type | Description |
---|---|
System.String | The comment or null if not set. |
Remarks
A comment is only available for entries when read via the ZipFile class. The ZipInputStream class doesn't have the comment data available.
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | If comment is longer than 0xffff. |
CompressedSize
Gets/Sets the size of the compressed data.
Declaration
public long CompressedSize { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 | The compressed entry size or -1 if unknown. |
CompressionMethod
Gets/Sets the compression method.
Declaration
public CompressionMethod CompressionMethod { get; set; }
Property Value
Type | Description |
---|---|
CompressionMethod | The compression method for this entry |
Crc
Gets/Sets the crc of the uncompressed data.
Declaration
public long Crc { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 | The crc value or -1 if unknown. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Crc is not in the range 0..0xffffffffL |
DateTime
Gets/Sets the time of last modification of the entry.
Declaration
public DateTime DateTime { get; set; }
Property Value
Type | Description |
---|---|
System.DateTime |
Remarks
The DosTime property is updated to match this as far as possible.
DosTime
Get/Set DosTime value.
Declaration
public long DosTime { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 |
Remarks
The MS-DOS date format can only represent dates between 1/1/1980 and 12/31/2107.
ExternalFileAttributes
Get/Set external file attributes as an integer. The values of this are operating system dependent see HostSystem for details
Declaration
public int ExternalFileAttributes { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
ExtraData
Gets/Sets the extra data.
Declaration
public byte[] ExtraData { get; set; }
Property Value
Type | Description |
---|---|
System.Byte[] | Extra data or null if not set. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Extra data is longer than 64KB (0xffff) bytes. |
Flags
Get/Set general purpose bit flag for entry
Declaration
public int Flags { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
General purpose bit flag
Bit 0: If set, indicates the file is encrypted
Bit 1-2 Only used for compression type 6 Imploding, and 8, 9 deflating
Imploding:
Bit 1 if set indicates an 8K sliding dictionary was used. If clear a 4k dictionary was used
Bit 2 if set indicates 3 Shannon-Fanno trees were used to encode the sliding dictionary, 2 otherwise
Deflating:
Bit 2 Bit 1
0 0 Normal compression was used
0 1 Maximum compression was used
1 0 Fast compression was used
1 1 Super fast compression was used
Bit 3: If set, the fields crc-32, compressed size
and uncompressed size are were not able to be written during zip file creation
The correct values are held in a data descriptor immediately following the compressed data.
Bit 4: Reserved for use by PKZIP for enhanced deflating
Bit 5: If set indicates the file contains compressed patch data
Bit 6: If set indicates strong encryption was used.
Bit 7-10: Unused or reserved
Bit 11: If set the name and comments for this entry are in unicode.
Bit 12-15: Unused or reserved
See Also
| Improve this Doc View SourceHasCrc
Get a value indicating whether the entry has a CRC value available.
Declaration
public bool HasCrc { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
HostSystem
Gets the compatibility information for the external file attribute If the external file attributes are compatible with MS-DOS and can be read by PKZIP for DOS version 2.04g then this value will be zero. Otherwise the value will be non-zero and identify the host system on which the attributes are compatible.
Declaration
public int HostSystem { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
The values for this as defined in the Zip File format and by others are shown below. The values are somewhat misleading in some cases as they are not all used as shown. You should consult the relevant documentation to obtain up to date and correct information. The modified appnote by the infozip group is particularly helpful as it documents a lot of peculiarities. The document is however a little dated.
IsCrypted
Get/Set flag indicating if entry is encrypted. A simple helper routine to aid interpretation of flags
Declaration
public bool IsCrypted { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
This is an assistant that interprets the flags property.
IsDirectory
Gets a value indicating if the entry is a directory. however.
Declaration
public bool IsDirectory { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
A directory is determined by an entry name with a trailing slash '/'. The external file attributes can also indicate an entry is for a directory. Currently only dos/windows attributes are tested in this manner. The trailing slash convention should always be followed.
IsDOSEntry
Get a value indicating this entry is for a DOS/Windows system.
Declaration
public bool IsDOSEntry { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsFile
Get a value of true if the entry appears to be a file; false otherwise
Declaration
public bool IsFile { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
This only takes account of DOS/Windows attributes. Other operating systems are ignored. For linux and others the result may be incorrect.
IsUnicodeText
Get / set a flag indicating whether entry name and comment text are encoded in unicode UTF8.
Declaration
public bool IsUnicodeText { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
This is an assistant that interprets the flags property.
LocalHeaderRequiresZip64
Gets a value indicating if the entry requires Zip64 extensions to store the full entry values.
Declaration
public bool LocalHeaderRequiresZip64 { get; }
Property Value
Type | Description |
---|---|
System.Boolean | A System.Boolean value of true if a local header requires Zip64 extensions; false if not. |
Name
Returns the entry name.
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The unix naming convention is followed. Path components in the entry should always separated by forward slashes ('/'). Dos device names like C: should also be removed. See the ZipNameTransform class, or CleanName(String)
Offset
Get/set offset for use in central header
Declaration
public long Offset { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 |
Size
Gets/Sets the size of the uncompressed data.
Declaration
public long Size { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 | The size or -1 if unknown. |
Remarks
Setting the size before adding an entry to an archive can help avoid compatibility problems with some archivers which don't understand Zip64 extensions.
Version
Get minimum Zip feature version required to extract this entry
Declaration
public int Version { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
Minimum features are defined as:
1.0 - Default value
1.1 - File is a volume label
2.0 - File is a folder/directory
2.0 - File is compressed using Deflate compression
2.0 - File is encrypted using traditional encryption
2.1 - File is compressed using Deflate64
2.5 - File is compressed using PKWARE DCL Implode
2.7 - File is a patch data set
4.5 - File uses Zip64 format extensions
4.6 - File is compressed using BZIP2 compression
5.0 - File is encrypted using DES
5.0 - File is encrypted using 3DES
5.0 - File is encrypted using original RC2 encryption
5.0 - File is encrypted using RC4 encryption
5.1 - File is encrypted using AES encryption
5.1 - File is encrypted using corrected RC2 encryption
5.1 - File is encrypted using corrected RC2-64 encryption
6.1 - File is encrypted using non-OAEP key wrapping
6.2 - Central directory encryption (not confirmed yet)
6.3 - File is compressed using LZMA
6.3 - File is compressed using PPMD+
6.3 - File is encrypted using Blowfish
6.3 - File is encrypted using Twofish
See Also
| Improve this Doc View SourceVersionMadeBy
Get the version made by for this entry or zero if unknown. The value / 10 indicates the major version number, and the value mod 10 is the minor version number
Declaration
public int VersionMadeBy { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
ZipFileIndex
Get/Set index of this entry in Zip file
Declaration
public long ZipFileIndex { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 |
Remarks
This is only valid when the entry is part of a ZipFile
Methods
| Improve this Doc View SourceCleanName(String)
Cleans a name making it conform to Zip file conventions. Devices names ('c:') and UNC share names ('\server\share') are removed and back slashes ('') are converted to forward slashes ('/'). Names are made relative by trimming leading slashes which is compatible with the ZIP naming convention.
Declaration
public static string CleanName(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name to clean |
Returns
Type | Description |
---|---|
System.String | The 'cleaned' name. |
Remarks
The Zip name transform class is more flexible.
Clone()
Creates a copy of this zip entry.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.Object | An System.Object that is a copy of the current instance. |
ForceZip64()
Force this entry to be recorded using Zip64 extensions.
Declaration
public void ForceZip64()
IsCompressionMethodSupported()
Test entry to see if data can be extracted.
Declaration
public bool IsCompressionMethodSupported()
Returns
Type | Description |
---|---|
System.Boolean | Returns true if data can be extracted for this entry; false otherwise. |
IsCompressionMethodSupported(CompressionMethod)
Test a compression method to see if this library supports extracting data compressed with that method
Declaration
public static bool IsCompressionMethodSupported(CompressionMethod method)
Parameters
Type | Name | Description |
---|---|---|
CompressionMethod | method | The compression method to test. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the compression method is supported; false otherwise |
IsZip64Forced()
Get a value indicating whether Zip64 extensions were forced.
Declaration
public bool IsZip64Forced()
Returns
Type | Description |
---|---|
System.Boolean | A System.Boolean value of true if Zip64 extensions have been forced on; false if not. |
ToString()
Gets a string representation of this ZipEntry.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A readable textual representation of this ZipEntry |