Class RarArchiveEntry

Class RarArchiveEntry

Namespace: Aspose.Zip.Rar
Assembly: Aspose.Zip.dll (25.2.0)

Represents single file within archive.

public abstract class RarArchiveEntry : IArchiveFileEntry

Inheritance

objectRarArchiveEntry

Derived

RarArchiveEntryEncrypted, RarArchiveEntryPlain

Implements

IArchiveFileEntry

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Remarks

Cast a Aspose.Zip.Rar.RarArchiveEntry instance to Aspose.Zip.Rar.RarArchiveEntryEncrypted to determine whether the entry encrypted or not.

Properties

CompressedSize

Gets size of compressed file.

public ulong CompressedSize { get; }

Property Value

ulong

CreationTime

Gets creation date and time.

public DateTime CreationTime { get; }

Property Value

DateTime

IsDirectory

Gets a value indicating whether the entry represents directory.

public bool IsDirectory { get; }

Property Value

bool

LastAccessTime

Gets last access date and time.

public DateTime LastAccessTime { get; }

Property Value

DateTime

ModificationTime

Gets last modified date and time.

public DateTime ModificationTime { get; }

Property Value

DateTime

Name

Gets name of the entry within archive.

public string Name { get; }

Property Value

string

Source

Gets the data source stream for the entry.

protected Stream Source { get; set; }

Property Value

Stream

UncompressedSize

Gets size of original file.

public ulong UncompressedSize { get; }

Property Value

ulong

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

FileInfo

The file info of composed file.

Examples

Extract two entries of rar archive.

using (FileStream rarFile = File.Open("archive.rar", FileMode.Open))
{
    using (RarArchive archive = new RarArchive(rarFile))
    {
        archive.Entries[0].Extract("first.bin", "pass");
        archive.Entries[1].Extract("second.bin", "pass");
    }
}

Exceptions

ArgumentNullException

path is null.

SecurityException

The caller does not have the required permission to access.

ArgumentException

The path is empty, contains only white spaces, or contains invalid characters.

UnauthorizedAccessException

Access to file path is denied.

PathTooLongException

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.

NotSupportedException

File at path contains a colon (:) in the middle of the string.

FileNotFoundException

The file is not found.

DirectoryNotFoundException

The specified path is invalid, such as being on an unmapped drive.

IOException

The file is already open.

InvalidDataException

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 rar archive with password.

using (FileStream rarFile = File.Open("archive.zip", FileMode.Open))
{
    using (RarArchive archive = new RarArchive(rarFile))
    {
        archive.Entries[0].Extract(httpResponseStream, "p@s$");
    }
}

Exceptions

InvalidDataException

CRC or MAC verification failed for the entry.

ArgumentException

destination does not support writing.

InvalidDataException

Data is corrupted. -or- CRC or MAC verification failed for the entry.

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. It can also be set within Aspose.Zip.Rar.RarArchiveLoadOptions.DecryptionPassword.

Returns

Stream

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>

### <a id="Aspose_Zip_Rar_RarArchiveEntry_ExtractionProgressed"></a> ExtractionProgressed

Raises when a portion of raw stream extracted.

```csharp
public event EventHandler<progresseventargs> ExtractionProgressed

Event Type

EventHandler<ProgressEventArgs&gt;

Examples

archive.Entries[0].ExtractionProgressed += (s, e) =&gt; { int percent = (int)((100 * e.ProceededBytes) / ((RarArchiveEntry)s).UncompressedSize); };

Remarks

Event sender is an Aspose.Zip.Rar.RarArchiveEntry instance.

 English