Class ArchiveEntry
Namespace: Aspose.Zip
Assembly: Aspose.Zip.dll (25.2.0)
Represents single file within archive.
public abstract class ArchiveEntry : IArchiveFileEntry
Inheritance
Derived
ArchiveEntryEncrypted, ArchiveEntryPlain
Implements
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Cast an Aspose.Zip.ArchiveEntry instance to Aspose.Zip.ArchiveEntryEncrypted to determine whether the entry encrypted or not.
Constructors
ArchiveEntry(string, CompressionSettings, Func<stream>, FileAttributes)
Initializes a new instance of the Aspose.Zip.ArchiveEntry class.
protected ArchiveEntry(string name, CompressionSettings compressionSettings, Func<stream> sourceProvider, FileAttributes fileAttributes)
Parameters
name
string
Entry name.
compressionSettings
CompressionSettings
Settings for compression or decompression.
sourceProvider
Func<Stream>
Method returning stream with entry data either to be compressed.
fileAttributes
FileAttributes
Attributes from file system.
ArchiveEntry(string, CompressionSettings, Stream, FileAttributes, FileSystemInfo)
Initializes a new instance of the Aspose.Zip.ArchiveEntry class.
protected ArchiveEntry(string name, CompressionSettings compressionSettings, Stream source, FileAttributes fileAttributes, FileSystemInfo fileInfo = null)
Parameters
name
string
Entry name.
compressionSettings
CompressionSettings
Settings for compression or decompression.
source
Stream
Stream with entry data either to be compressed or to be decompressed.
fileAttributes
FileAttributes
Attributes from file system.
fileInfo
FileSystemInfo
File or directory info the entry based on.
Properties
Comment
Gets comment of the entry within archive.
public string Comment { get; protected set; }
Property Value
CompressedSize
Gets size of compressed file.
public ulong CompressedSize { get; }
Property Value
CompressionSettings
Gets settings for compression or decompression.
public CompressionSettings CompressionSettings { get; }
Property Value
DataSource
Source for the entry if the entry was added to archive, not extracted.
public Stream DataSource { get; }
Property Value
Remarks
Before assigned, the source is null. This source may be assigned within Archive.Save
method in some cases.
FileAttributes
Gets file attributes from host system.
protected FileAttributes FileAttributes { get; }
Property Value
IsDirectory
Gets a value indicating whether the entry represents a directory.
public bool IsDirectory { get; }
Property Value
ModificationTime
Gets or sets last modified date and time.
public DateTime ModificationTime { get; set; }
Property Value
Name
Gets name of the entry within archive.
public string Name { get; protected set; }
Property Value
UncompressedSize
Gets size of original file.
public ulong UncompressedSize { get; }
Property Value
Methods
Extract(string, string)
Extracts the entry to the filesystem by the path provided.
public FileInfo Extract(string path, string password = null)
Parameters
path
string
The path to destination file. If the file already exists, it will be overwritten.
password
string
Optional password for decryption.
Returns
The file info of composed file.
Examples
Extract two entries of zip archive, each with own password
using (FileStream zipFile = File.Open("archive.zip", FileMode.Open))
{
using (Archive archive = new Archive(zipFile))
{
archive.Entries[0].Extract("first.bin", "first_pass");
archive.Entries[1].Extract("second.bin", "second_pass");
}
}
Exceptions
path
is null.
The caller does not have the required permission to access.
The path
is empty, contains only white spaces, or contains invalid characters.
Access to file path
is denied.
The specified path
, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
File at path
contains a colon (:) in the middle of the string.
The file is not found.
The specified path is invalid, such as being on an unmapped drive.
The file is already open.
Data is corrupted. -or- CRC or MAC verification failed for the entry.
Extract(Stream, string)
Extracts the entry to the stream provided.
public void Extract(Stream destination, string password = null)
Parameters
destination
Stream
Destination stream. Must be writable.
password
string
Optional password for decryption.
Examples
Extract an entry of zip archive with password.
using (FileStream zipFile = File.Open("archive.zip", FileMode.Open))
{
using (Archive archive = new Archive(zipFile))
{
archive.Entries[0].Extract(httpResponseStream, "p@s$");
}
}
Exceptions
Data is corrupted. -or- CRC or MAC verification failed for the entry.
Source is corrupted or not readable.
destination
does not support writing.
Open(string)
Opens the entry for extraction and provides a stream with decompressed entry content.
public Stream Open(string password = null)
Parameters
password
string
Optional password for decryption.
Returns
The stream that represents the contents of the entry.
Examples
Usage:
Stream decompressed = entry.Open();
.NET 4.0 and higher - use Stream.CopyTo method:
decompressed.CopyTo(httpResponse.OutputStream)
.NET 3.5 and before - copy bytes manually:
byte[] buffer = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.Read(buffer, 0, buffer.Length)))
fileStream.Write(buffer, 0, bytesRead);
```</p>
#### Remarks
<p>Read from the stream to get original content of file. See examples section.</p>
#### Exceptions
[InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception)
The archive is in incorrect state.
### <a id="Aspose_Zip_ArchiveEntry_CompressionProgressed"></a> CompressionProgressed
Raises when a portion of raw stream compressed.
```csharp
public event EventHandler<progresseventargs> CompressionProgressed
Event Type
EventHandler<ProgressEventArgs>
Examples
archive.Entries[0].CompressionProgressed += (s, e) => { int percent = (int)((100 * (long)e.ProceededBytes) / entrySourceStream.Length); };
Remarks
Event sender is an Aspose.Zip.ArchiveEntry instance.
ExtractionProgressed
Raises when a portion of raw stream extracted.
public event EventHandler<progresseventargs> ExtractionProgressed
Event Type
EventHandler<ProgressEventArgs>
Examples
archive.Entries[0].ExtractionProgressed += (s, e) => { int percent = (int)((100 * e.ProceededBytes) / ((ArchiveEntry)s).UncompressedSize); };
Remarks
Event sender is an Aspose.Zip.ArchiveEntry instance. </stream>