ZipArchiveEntry Class
An entry of a zip archive: an entry of the central directory of a ZipArchive, a new entry of an archive in ZipArchiveMode.Create or ZipArchiveMode.Update mode, or an entry of the local headers of a forward-only reader. A local header does not have the comment, the "version made by" and the external attributes of the entry: a forward-only reader returns an empty comment, 0, and no attributes, permissions or link target.
public sealed class ZipArchiveEntry : ArchiveEntryRemarks
The metadata of a new entry are changed with the Set methods (the properties of ArchiveEntry are read-only): the time before its content is opened, since the local header that precedes the content stores it; the comment, the attributes and the permissions until the archive is disposed. In ZipArchiveMode.Update mode, the comment, the attributes and the permissions of an existing entry can be changed too: they are stored in the central directory only.
- Inheritance
ArchiveEntryZipArchiveEntry
Properties
| Name | Description |
|---|---|
| Archive | Gets the archive of the entry, or null for an entry of a forward-only reader. |
| Attributes | Gets the Windows attributes of an entry created on MS-DOS or Windows (FAT, NTFS, VFAT, OS/2), or null. |
| Comment | Gets the comment of the entry, or an empty string. |
| CompressedLength | Gets the length of the content of the entry in the archive (compressed and encrypted). A forward-only reader returns -1 for a streamed entry until its content is read, and a new entry until its content is written. |
| CompressionMethod | Gets the compression method of the entry. For an AES-encrypted entry (method 99 in the headers), it is the method of the AES extra field. A value that is not a member of ZipCompressionMethod is an unknown method. |
| Crc32 | Gets the CRC-32 of the content, or null when the archive does not store it: an AES entry of version AE-2, a streamed entry of a forward-only reader before its content is read, or a new entry before its content is written. |
| CreationTime | Gets the time the entry was created, from the NTFS extra field (or the extended timestamp of a local header), or null. |
| EncryptionMethod | Gets the encryption of the content of the entry. |
| ExternalAttributes | Gets the external attributes of the entry: MS-DOS attributes in the low 16 bits, and a Unix mode in the high 16 bits for an entry created on Unix. |
| FullName | Gets the path of the entry in the archive, with / separators. |
| GeneralPurposeFlags | Gets the general purpose bit flags of the entry. |
| IsDirectory | Gets a value indicating whether the entry is a directory: its name ends with /, or its attributes say so. |
| IsEncrypted | Gets a value indicating whether the content of the entry is encrypted. |
| LastAccessTime | Gets the last time the entry was accessed, from the NTFS extra field (or the extended timestamp of a local header), or null. |
| LastWriteTime | Gets the last time the entry was modified: the NTFS time (extra field 0x000A) or the Unix time (extra field 0x5455) when the entry has one, in UTC; otherwise the MS-DOS time of the header, which has no time zone and is returned as a time of the local time zone, as ZipArchiveEntry.LastWriteTime does. It is null when the MS-DOS time is not a valid date. |
| Length | Gets the length of the content of the entry. A forward-only reader returns -1 for a streamed entry (an entry with a data descriptor) until its content is read: the data descriptor that follows the content gives it. A new entry returns -1 until its content is written. |
| LinkTarget | Gets the target of a symbolic link: the content of an entry whose Unix mode is a symbolic link (S_IFLNK). Reading it reads the content of the entry, decoded as the name is (UTF-8 when the name is not marked as UTF-8 and the options do not set an encoding), and may throw the exceptions of ZipArchiveEntry.Open. |
| UnixFileMode | Gets the permissions of an entry created on Unix or macOS, or null. |
| VersionMadeBy | Gets the "version made by" field of the central directory: the operating system that created the entry in the high byte, and the version of the specification in the low byte. |
Archive
ZipArchiveEntry.csGets the archive of the entry, or null for an entry of a forward-only reader.
public ZipArchive? Archive { get; }Property value
Attributes
ZipArchiveEntry.csGets the Windows attributes of an entry created on MS-DOS or Windows (FAT, NTFS, VFAT, OS/2), or null.
public override FileAttributes? Attributes { get; }Property value
Comment
ZipArchiveEntry.csCompressedLength
ZipArchiveEntry.csCompressionMethod
ZipArchiveEntry.csGets the compression method of the entry. For an AES-encrypted entry (method 99 in the headers), it is the method of the AES extra field. A value that is not a member of ZipCompressionMethod is an unknown method.
public ZipCompressionMethod CompressionMethod { get; }Property value
Crc32
ZipArchiveEntry.csCreationTime
ZipArchiveEntry.csGets the time the entry was created, from the NTFS extra field (or the extended timestamp of a local header), or null.
public override DateTimeOffset? CreationTime { get; }Property value
EncryptionMethod
ZipArchiveEntry.csGets the encryption of the content of the entry.
public ZipEncryption EncryptionMethod { get; }Property value
ExternalAttributes
ZipArchiveEntry.csFullName
ZipArchiveEntry.csGeneralPurposeFlags
ZipArchiveEntry.csIsDirectory
ZipArchiveEntry.csIsEncrypted
ZipArchiveEntry.csLastAccessTime
ZipArchiveEntry.csGets the last time the entry was accessed, from the NTFS extra field (or the extended timestamp of a local header), or null.
public override DateTimeOffset? LastAccessTime { get; }Property value
LastWriteTime
ZipArchiveEntry.csGets the last time the entry was modified: the NTFS time (extra field 0x000A) or the Unix time (extra field 0x5455) when the entry has one, in UTC; otherwise the MS-DOS time of the header, which has no time zone and is returned as a time of the local time zone, as ZipArchiveEntry.LastWriteTime does. It is null when the MS-DOS time is not a valid date.
public override DateTimeOffset? LastWriteTime { get; }Property value
Length
ZipArchiveEntry.csGets the length of the content of the entry. A forward-only reader returns -1 for a streamed entry (an entry with a data descriptor) until its content is read: the data descriptor that follows the content gives it. A new entry returns -1 until its content is written.
public override long Length { get; }Property value
LinkTarget
ZipArchiveEntry.csGets the target of a symbolic link: the content of an entry whose Unix mode is a symbolic link (S_IFLNK). Reading it reads the content of the entry, decoded as the name is (UTF-8 when the name is not marked as UTF-8 and the options do not set an encoding), and may throw the exceptions of ZipArchiveEntry.Open.
public override string? LinkTarget { get; }Property value
UnixFileMode
ZipArchiveEntry.csGets the permissions of an entry created on Unix or macOS, or null.
public override UnixFileMode? UnixFileMode { get; }Property value
VersionMadeBy
ZipArchiveEntry.csMethods
| Name | Description |
|---|---|
| Delete() | Deletes the entry from the archive. |
| Open() | Opens the content of the entry: a read-only stream for an entry of the archive, or a write-only stream for a new entry (once; disposing it completes the entry). The read stream checks the length and the CRC-32 of the content (or the authentication code of an AES entry) and throws an InvalidDataException at its end when they do not match. The streams of the entries of a ZipArchive can be read alternately, but not from several threads at once. One new entry is written at a time. |
| SetAttributes(FileAttributes?) | Sets the MS-DOS attributes of the entry: the low 16 bits of the external attributes. The Unix permissions are kept. |
| SetComment(string?) | Sets the comment of the entry. |
| SetLastWriteTime(DateTimeOffset) | Sets the last time the entry was modified. It can be set until the content of a new entry is opened. |
| SetUnixFileMode(UnixFileMode?) | Sets the Unix permissions of the entry. The entry is then marked as created on Unix, and the high 16 bits of its external attributes are its mode: its type (a file, a directory or a symbolic link) and its permissions. |
Delete()
ZipArchiveEntry.csDeletes the entry from the archive.
public void Delete()Exceptions
NotSupportedException- The archive is not in
ZipArchiveMode.Updatemode. InvalidOperationException- The content of the entry is being written.
Open()
ZipArchiveEntry.csOpens the content of the entry: a read-only stream for an entry of the archive, or a write-only stream for a new entry (once; disposing it completes the entry). The read stream checks the length and the CRC-32 of the content (or the authentication code of an AES entry) and throws an InvalidDataException at its end when they do not match. The streams of the entries of a ZipArchive can be read alternately, but not from several threads at once. One new entry is written at a time.
public override Stream Open()Returns
Stream A stream of the content of the entry.
Exceptions
InvalidDataException- The archive is corrupted.
ArchivePasswordException- The entry is encrypted and the password is missing or wrong.
NotSupportedException- The entry is compressed or encrypted with a method that is not supported.
InvalidOperationException- The new entry is a directory, or another new entry is being written.
IOException- The new entry is already written.
SetAttributes(FileAttributes?)
ZipArchiveEntry.csSets the MS-DOS attributes of the entry: the low 16 bits of the external attributes. The Unix permissions are kept.
public void SetAttributes(FileAttributes? value)Parameters
valueFileAttributes?- The attributes, or
nullfor none (FileAttributes.Directoryfor a directory).
SetComment(string?)
ZipArchiveEntry.csSets the comment of the entry.
Parameters
valuestring?- The comment, or
nullfor none.
Exceptions
ArgumentException- The comment is longer than 65535 bytes.
SetLastWriteTime(DateTimeOffset)
ZipArchiveEntry.csSets the last time the entry was modified. It can be set until the content of a new entry is opened.
public void SetLastWriteTime(DateTimeOffset value)Parameters
valueDateTimeOffset- The time.
Exceptions
NotSupportedException- The entry is not a new entry.
InvalidOperationException- The content of the entry is opened already: its local header is written.
SetUnixFileMode(UnixFileMode?)
ZipArchiveEntry.csSets the Unix permissions of the entry. The entry is then marked as created on Unix, and the high 16 bits of its external attributes are its mode: its type (a file, a directory or a symbolic link) and its permissions.
public void SetUnixFileMode(UnixFileMode? value)Parameters
valueUnixFileMode?- The permissions, or
nullto mark the entry as created on MS-DOS, without permissions.