Class RarArchive
Namespace: Aspose.Zip.Rar
Assembly: Aspose.Zip.dll (25.8.0)
This class represents RAR archive file. Use it to extract RAR archives.
public class RarArchive : IArchive, IDisposableInheritance
Implements
Inherited Members
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Constructors
RarArchive(string, RarArchiveLoadOptions)
Initializes a new instance of the Aspose.Zip.Rar.RarArchive class and composes an entry list can be extracted from the archive.
public RarArchive(string path, RarArchiveLoadOptions loadOptions = null)Parameters
path string
The fully qualified or the relative path to the archive file.
loadOptions RarArchiveLoadOptions
Options to load existing archive with.
Examples
The following example extracts an archive, then decompress first entry to a MemoryStream.
var extracted = new MemoryStream();
using (RarArchive archive = new RarArchive("data.rar"))
{
using (var decompressed = archive.Entries[0].Open())
{
byte[] b = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.Read(b, 0, b.Length)))
extracted.Write(b, 0, bytesRead);
}
}Remarks
This constructor does not decompress any entry. See Aspose.Zip.Rar.RarArchiveEntry.Open(System.String) method for decompressing.
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.
RarArchive(Stream, RarArchiveLoadOptions)
Initializes a new instance of the Aspose.Zip.Rar.RarArchive class and composes an entry list can be extracted from the archive.
public RarArchive(Stream sourceStream, RarArchiveLoadOptions loadOptions = null)Parameters
sourceStream Stream
The source of the archive.
loadOptions RarArchiveLoadOptions
Options to load existing archive with.
Examples
The following example decipher and decompress first entry to a MemoryStream.
var fs = File.OpenRead("encrypted.rar");
var extracted = new MemoryStream();
using (RarArchive archive = new RarArchive(fs, new RarArchiveLoadOptions() { DecryptionPassword = "p@s$" }))
{
using (var decompressed = archive.Entries[0].Open())
{
byte[] b = new byte[8192];
int bytesRead;
while (0 < (bytesRead = decompressed.Read(b, 0, b.Length)))
extracted.Write(b, 0, bytesRead);
}
}Remarks
This constructor does not decompress any entry. See Aspose.Zip.Rar.RarArchiveEntry.Open(System.String) method for decompressing.
Exceptions
sourceStream is not seekable.
Wrong signature for archive. - or - The file is not a RAR archive.
Properties
Entries
Gets entries of Aspose.Zip.Rar.RarArchiveEntry type constituting the rar archive.
public ReadOnlyCollection<rararchiveentry> Entries { get; }Property Value
ReadOnlyCollection < RarArchiveEntry >
Methods
Dispose(bool)
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
protected virtual void Dispose(bool disposing)Parameters
disposing bool
Whether managed resources should be disposed.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()ExtractToDirectory(string, string)
Extracts all the files in the archive to the directory provided.
[Obsolete("For extraction encrypted RAR archive please provide password in constructor with Aspose.Zip.Rar.RarArchiveLoadOptions.DecryptionPassword")]
public void ExtractToDirectory(string destinationDirectory, string password = null)Parameters
destinationDirectory string
The path to the directory to place the extracted files in.
password string
Optional password for decryption.
Examples
using (var archive = new RarArchive("archive.rar"))
{
archive.ExtractToDirectory("C:\extracted", "$ecRet");
}Remarks
If the directory does not exist, it will be created.
Exceptions
destinationDirectory is null.
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.
The caller does not have the required permission to access the existing directory.
If the directory does not exist, the path contains a colon character (:) that is not part of a drive label (“C:").
destinationDirectory is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the System.IO.Path.GetInvalidPathChars method. -or- path is prefixed with, or contains, only a colon character (:).
The directory specified by path is a file. -or- The network name is not known.
Archive has been disposed and cannot be used.
ExtractToDirectory(string)
Extracts all the files in the archive to the directory provided.
public void ExtractToDirectory(string destinationDirectory)Parameters
destinationDirectory string
The path to the directory to place the extracted files in.
Examples
using (var archive = new RarArchive("archive.rar"))
{
archive.ExtractToDirectory("C:\extracted");
}Remarks
If the directory does not exist, it will be created.
For extraction encrypted RarArchive use Aspose.Zip.Rar.RarArchiveLoadOptions.DecryptionPassword
Exceptions
destinationDirectory is null.
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.
The caller does not have the required permission to access the existing directory.
If the directory does not exist, the path contains a colon character (:) that is not part of a drive label (“C:").
destinationDirectory is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the System.IO.Path.GetInvalidPathChars method. -or- path is prefixed with, or contains, only a colon character (:).
The directory specified by path is a file. -or- The network name is not known.
Archive has been disposed and cannot be used.