Class SevenZipLoadOptions

Class SevenZipLoadOptions

Namespace: Aspose.Zip.SevenZip
Assembly: Aspose.Zip.dll (25.7.0)

Options with which Aspose.Zip.SevenZip.SevenZipArchive is loaded from a compressed file.

public class SevenZipLoadOptions

Inheritance

object SevenZipLoadOptions

Inherited Members

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

Constructors

SevenZipLoadOptions()

public SevenZipLoadOptions()

Properties

CancellationToken

Gets or sets a cancellation token used to cancel the extraction operation.

public CancellationToken CancellationToken { get; set; }

Property Value

CancellationToken

Examples

Cancel 7Z archive extraction after a certain time.

using (CancellationTokenSource cts = new CancellationTokenSource())
{
    cts.CancelAfter(TimeSpan.FromSeconds(60)); 
    using (var a = new SevenZipArchive("big.7z", new SevenZipLoadOptions() { 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 SevenZipLoadOptions() { CancellationToken = cts.Token };
                                                   using (var a = new SevenZipArchive("big.7z", 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_SevenZip_SevenZipLoadOptions_DecryptionPassword"></a> DecryptionPassword

Gets or sets the password to decrypt entries and entry names.

```csharp
public string DecryptionPassword { get; set; }

Property Value

string

Examples

You can provide decryption password once on archive extraction.

using (FileStream fs = File.OpenRead("encrypted_archive.7z"))
{
    using (var extracted = File.Create("extracted.bin"))
    {
        using (SevenZipArchive archive = new SevenZipArchive(fs, new SevenZipLoadOptions() { DecryptionPassword = "p@s$" }))
        {
            using (var decompressed = archive.Entries[0].Open())
            {
                byte[] b = new byte[8192];
                int bytesRead;
                while (0 &lt; (bytesRead = decompressed.Read(b, 0, b.Length)))
                    extracted.Write(b, 0, bytesRead);

            }
        }
    }
}

See Also

SevenZipArchiveEntry . Open ( string )