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 : ArchiveEntry

Remarks

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
ArchiveEntry ZipArchiveEntry

Properties

NameDescription
ArchiveGets the archive of the entry, or null for an entry of a forward-only reader.
AttributesGets the Windows attributes of an entry created on MS-DOS or Windows (FAT, NTFS, VFAT, OS/2), or null.
CommentGets the comment of the entry, or an empty string.
CompressedLengthGets 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.
CompressionMethodGets 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.
Crc32Gets 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.
CreationTimeGets the time the entry was created, from the NTFS extra field (or the extended timestamp of a local header), or null.
EncryptionMethodGets the encryption of the content of the entry.
ExternalAttributesGets 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.
FullNameGets the path of the entry in the archive, with / separators.
GeneralPurposeFlagsGets the general purpose bit flags of the entry.
IsDirectoryGets a value indicating whether the entry is a directory: its name ends with /, or its attributes say so.
IsEncryptedGets a value indicating whether the content of the entry is encrypted.
LastAccessTimeGets the last time the entry was accessed, from the NTFS extra field (or the extended timestamp of a local header), or null.
LastWriteTimeGets 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.
LengthGets 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.
LinkTargetGets 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.
UnixFileModeGets the permissions of an entry created on Unix or macOS, or null.
VersionMadeByGets 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.

Gets the archive of the entry, or null for an entry of a forward-only reader.

public ZipArchive? Archive { get; }

Property value

ZipArchive?

Gets 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

FileAttributes?

Gets the comment of the entry, or an empty string.

public string Comment { get; }

Property value

string

CompressedLength

ZipArchiveEntry.cs

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.

public override long CompressedLength { get; }

Property value

long

CompressionMethod

ZipArchiveEntry.cs

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.

public ZipCompressionMethod CompressionMethod { get; }

Property value

ZipCompressionMethod

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.

public override uint? Crc32 { get; }

Property value

uint?

CreationTime

ZipArchiveEntry.cs

Gets 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

DateTimeOffset?

EncryptionMethod

ZipArchiveEntry.cs

Gets the encryption of the content of the entry.

public ZipEncryption EncryptionMethod { get; }

Property value

ZipEncryption

ExternalAttributes

ZipArchiveEntry.cs

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.

public int ExternalAttributes { get; }

Property value

int

Gets the path of the entry in the archive, with / separators.

public override string FullName { get; }

Property value

string

GeneralPurposeFlags

ZipArchiveEntry.cs

Gets the general purpose bit flags of the entry.

public ushort GeneralPurposeFlags { get; }

Property value

ushort

Gets a value indicating whether the entry is a directory: its name ends with /, or its attributes say so.

public override bool IsDirectory { get; }

Property value

bool

Gets a value indicating whether the content of the entry is encrypted.

public override bool IsEncrypted { get; }

Property value

bool

LastAccessTime

ZipArchiveEntry.cs

Gets 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

DateTimeOffset?

LastWriteTime

ZipArchiveEntry.cs

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.

public override DateTimeOffset? LastWriteTime { get; }

Property value

DateTimeOffset?

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.

public override long Length { get; }

Property value

long

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.

public override string? LinkTarget { get; }

Property value

string?

UnixFileMode

ZipArchiveEntry.cs

Gets the permissions of an entry created on Unix or macOS, or null.

public override UnixFileMode? UnixFileMode { get; }

Property value

UnixFileMode?

VersionMadeBy

ZipArchiveEntry.cs

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.

public ushort VersionMadeBy { get; }

Property value

ushort

Methods

NameDescription
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.

Deletes the entry from the archive.

public void Delete()

Exceptions

NotSupportedException
The archive is not in ZipArchiveMode.Update mode.
InvalidOperationException
The content of the entry is being written.

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.

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.cs

Sets 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

value FileAttributes?
The attributes, or null for none (FileAttributes.Directory for a directory).

SetComment(string?)

ZipArchiveEntry.cs

Sets the comment of the entry.

public void SetComment(string? value)

Parameters

value string?
The comment, or null for none.

Exceptions

ArgumentException
The comment is longer than 65535 bytes.

SetLastWriteTime(DateTimeOffset)

ZipArchiveEntry.cs

Sets 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

value DateTimeOffset
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.cs

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.

public void SetUnixFileMode(UnixFileMode? value)

Parameters

value UnixFileMode?
The permissions, or null to mark the entry as created on MS-DOS, without permissions.