RarArchive Class

A RAR archive (RAR 1.5-4.x or RAR5) opened for random access from a seekable stream. It reads the archives created by an SFX module, solid archives (an entry is decoded after the entries it depends on), multi-volume archives (see ArchiveReaderOptions.VolumeResolver), and archives encrypted with AES, including their headers.

public sealed class RarArchive : Archive

Example

using var stream = File.OpenRead(path);
using var archive = new RarArchive(stream);
Assert.Equal(RarFormatVersion.Rar5, archive.FormatVersion);
Assert.True(archive.IsSolid);
foreach (var entry in archive.Entries)
{
    using var content = entry.Open();
    using var buffer = new MemoryStream();
    content.CopyTo(buffer);
    Assert.Equal(entry.Length, buffer.Length);
}
Inheritance
Archive RarArchive

Constructors

NameDescription
RarArchive(Stream, ArchiveReaderOptions?, bool)Opens a RAR archive from a seekable stream.

RarArchive(Stream, ArchiveReaderOptions?, bool)

RarArchive.cs

Opens a RAR archive from a seekable stream.

public RarArchive(Stream stream, ArchiveReaderOptions? options = null, bool leaveOpen = false)

Parameters

stream Stream
The first volume of the archive. It must be readable and seekable.
options ArchiveReaderOptions?
The options, or null for the defaults.
leaveOpen bool
true to leave stream open after the archive is disposed.

Exceptions

ArgumentException
stream is not readable or not seekable.
InvalidDataException
The stream is not a RAR archive, or the archive is corrupted.
ArchivePasswordException
The headers are encrypted and the password is missing or wrong.
NotSupportedException
The archive is a RAR 1.4 archive, or uses an encryption that is not supported.

Properties

NameDescription
CommentGets the comment of the archive, or null when there is none, or when it cannot be decoded (a RAR 1.5 compression, a missing password, corrupted data).
EntriesGets the entries of the archive, in the order of the archive. The service headers (comments, quick open data, ...) are not entries.
FormatGets the format of the archive.
FormatVersionGets the version of the format of the archive.
IsMultiVolumeGets a value indicating whether the archive is a volume of a multi-volume archive.
IsSolidGets a value indicating whether the archive is solid: the entries continue the compression dictionary of the previous ones.
VolumeCountGets the number of volumes that were read.

Gets the comment of the archive, or null when there is none, or when it cannot be decoded (a RAR 1.5 compression, a missing password, corrupted data).

public string? Comment { get; }

Property value

string?

Gets the entries of the archive, in the order of the archive. The service headers (comments, quick open data, ...) are not entries.

public new IReadOnlyList<RarArchiveEntry> Entries { get; }

Gets the format of the archive.

public override ArchiveFormat Format { get; }

Property value

ArchiveFormat

FormatVersion

RarArchive.cs

Gets the version of the format of the archive.

public RarFormatVersion FormatVersion { get; }

Property value

RarFormatVersion

IsMultiVolume

RarArchive.cs

Gets a value indicating whether the archive is a volume of a multi-volume archive.

public bool IsMultiVolume { get; }

Property value

bool

Gets a value indicating whether the archive is solid: the entries continue the compression dictionary of the previous ones.

public bool IsSolid { get; }

Property value

bool

VolumeCount

RarArchive.cs

Gets the number of volumes that were read.

public int VolumeCount { get; }

Property value

int

Methods

NameDescription
GetEntry(string)Gets the entry whose full name is entryName (an ordinal comparison), or null when there is none.

GetEntry(string)

RarArchive.cs

Gets the entry whose full name is entryName (an ordinal comparison), or null when there is none.

public new RarArchiveEntry? GetEntry(string entryName)

Parameters

entryName string
The path of the entry in the archive, with / separators.

Returns

RarArchiveEntry? The first entry whose ArchiveEntry.FullName is entryName, or null.