Class RarArchiveLoadOptions
Class RarArchiveLoadOptions
Namespace: Aspose.Zip.Rar
Assembly: Aspose.Zip.dll (25.7.0)
Options with which Aspose.Zip.Rar.RarArchive is loaded from a compressed file.
public class RarArchiveLoadOptions
Inheritance
object ← RarArchiveLoadOptions
Inherited Members
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Constructors
RarArchiveLoadOptions()
public RarArchiveLoadOptions()
Properties
CancellationToken
Gets or sets a cancellation token used to cancel the extraction operation.
public CancellationToken CancellationToken { get; set; }
Property Value
Examples
Cancel RAR archive extraction after a certain time.
using (CancellationTokenSource cts = new CancellationTokenSource())
{
cts.CancelAfter(TimeSpan.FromSeconds(60));
using (var a = new RarArchive("big.rar", new RarArchiveLoadOptions() { CancellationToken = cts.Token }))
{
try
{
a.Entries[0].Extract("data.bin");
}
catch(OperationCanceledException)
{
Console.WriteLine("Extraction was cancelled after 60 seconds");
}
}
}
```<p>
Using with <code>Task</code>
```csharp
CancellationTokenSource cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(60));
Task t = Task.Run(delegate()
{
var loadOptions = new RarArchiveLoadOptions() { CancellationToken = cts.Token };
using (var a = new RarArchive("big.rar", loadOptions))
{
a.ExtractToDirectory("destination");
}
}, cts.Token);
t.ContinueWith(delegate(Task antecedent)
{
if (antecedent.IsCanceled)
{
Console.WriteLine("Extraction was cancelled after 60 seconds");
}
cts.Dispose();
});
```</p>
Cancellation mostly results in some data not being extracted.
#### Remarks
This property exists for .NET Framework 4.0 and above.
### <a id="Aspose_Zip_Rar_RarArchiveLoadOptions_DecryptionPassword"></a> DecryptionPassword
Gets or sets the password to decrypt entries and entry names.
```csharp
public string DecryptionPassword { get; set; }
Property Value
Examples
You can provide decryption password once on archive extraction.
using (FileStream fs = File.OpenRead("encrypted_archive.rar"))
{
using (var extracted = File.Create("extracted.bin"))
{
using (RarArchive archive = new RarArchive(fs, new ArchiveLoadOptions() { 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);
}
}
}
}
See Also
RarArchiveEntry . Open ( string )