Class Bzip2LoadOptions
Class Bzip2LoadOptions
Namespace: Aspose.Zip.Bzip2
Assembly: Aspose.Zip.dll (25.7.0)
Options for loading Aspose.Zip.Bzip2.Bzip2Archive. Contains event raised on extraction.
public class Bzip2LoadOptions
Inheritance
Inherited Members
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Constructors
Bzip2LoadOptions()
public Bzip2LoadOptions()
Properties
CancellationToken
Gets or sets a cancellation token used to cancel the extraction operation.
public CancellationToken CancellationToken { get; set; }
Property Value
Examples
Cancel Bzip2 archive extraction after a certain time.
using (CancellationTokenSource cts = new CancellationTokenSource())
{
cts.CancelAfter(TimeSpan.FromSeconds(60));
using (var a = new Bzip2Archive("big.bz2", new Bzip2LoadOptions() { CancellationToken = cts.Token }))
{
try
{
a.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 Bzip2LoadOptions() { CancellationToken = cts.Token };
using (var a = Bzip2Archive("big.bz2", 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_Bzip2_Bzip2LoadOptions_ExtractionProgressed"></a> ExtractionProgressed
Event raised invoked when some bytes have been extracted.
```csharp
public event EventHandler<progresseventargs> ExtractionProgressed
Event Type
EventHandler < ProgressEventArgs >
Examples
Bzip2LoadOptions loadOptions = new Bzip2LoadOptions();
loadOptions.ExtractionProgressed += (s, e) => { percent = (int) ((double)(100 * e.ProceededBytes) / originalFileLength); };
Remarks
Event sender is the Aspose.Zip.Bzip2.Bzip2Archive instance which extraction is progressed. The Aspose.Zip.ProgressEventArgs.ProceededBytes is the number of bytes after extraction.