Class SevenZipArchiveEntry
Namespace: Aspose.Zip.SevenZip
Assembly: Aspose.Zip.dll (25.8.0)
Represents a single file within 7z archive.
public abstract class SevenZipArchiveEntry : IArchiveFileEntryInheritance
Derived
SevenZipArchiveEntryEncrypted , SevenZipArchiveEntryPlain
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.SevenZip.SevenZipArchiveEntry instance to Aspose.Zip.SevenZip.SevenZipArchiveEntryEncrypted to determine whether the entry encrypted or not.
Properties
CompressedSize
Gets the size of a compressed file.
public ulong CompressedSize { get; }Property Value
CompressionSettings
Gets settings for compression or decompression.
public SevenZipCompressionSettings CompressionSettings { get; }Property Value
FileAttributes
Gets file attributes from a 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 last modified date and time.
public DateTime ModificationTime { get; }Property Value
Name
Gets name of the entry within the archive.
public string Name { get; protected set; }Property Value
Source
Gets the data source stream for the entry.
protected Stream Source { get; }Property Value
UncompressedSize
Gets size of an 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 a composed file.
Examples
using (var archive = new SevenZipArchive("archive.7z"))
{
archive.Entries[0].Extract("data.bin");
}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 archive is corrupted.
In .NET Framework 4.0 and above: Thrown when the extraction is canceled via the provided cancellation token.
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 (var archive = new SevenZipArchive("archive.7z"))
{
archive.Entries[0].Extract(httpResponseStream);
}Exceptions
destination does not support writing.
The archive is not opened for extraction. - or - This entry is a directory.
Wrong data within the entry.
In .NET Framework 4.0 and above: Thrown when the extraction is canceled via the provided cancellation token.
FinalizeCompressedData(Stream, byte[])
Write to output stream any headers that follow compressed data.
protected abstract int FinalizeCompressedData(Stream outputStream, byte[] encoderProperties)Parameters
outputStream Stream
Output stream for the entry.
encoderProperties byte
[]
Properties of compressor.
Returns
Number of “technical” bytes that were added after entry significant data block.
GetDestinationStream(Stream)
Destination stream for the entry, may be decorated.
protected abstract Stream GetDestinationStream(Stream outputStream)Parameters
outputStream Stream
Output stream for the entry.
Returns
The destination stream for entry compression.
Open(string)
Opens the entry for extraction and provides a stream with 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
Read from the stream to get the original content of a file. See examples section.
#### Exceptions
[InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception)
The archive is not opened for extraction. - or - This entry is a directory.
[InvalidDataException](https://learn.microsoft.com/dotnet/api/system.io.invaliddataexception)
Wrong data within the entry.
### <a id="Aspose_Zip_SevenZip_SevenZipArchiveEntry_CompressionProgressed"></a> CompressionProgressed
Raises when a portion of raw stream compressed.
```csharp
public event EventHandler<progresseventargs> CompressionProgressedEvent 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.SevenZip.SevenZipArchiveEntry instance.
Does not invoke in solid mode and in multithreaded mode for LZMA2 entries.