Class ArchiveLoadOptions

Class ArchiveLoadOptions

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

Options with which archive is loaded from a compressed file.

public class ArchiveLoadOptions

Inheritance

object ArchiveLoadOptions

Inherited Members

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

Constructors

ArchiveLoadOptions()

public ArchiveLoadOptions()

Properties

CancellationToken

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

public CancellationToken CancellationToken { get; set; }

Property Value

CancellationToken

Examples

Cancel ZIP archive extraction after a certain time.

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

Gets or sets the password to decrypt entries.

```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.zip"))
{
    using (var extracted = File.Create("extracted.bin"))
    {
        using (var archive = new Archive(fs, new ArchiveLoadOptions() { 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

ArchiveEntry . Open ( string )

Encoding

Gets or sets the encoding for entries’ names.

public Encoding Encoding { get; set; }

Property Value

Encoding

Examples

Entry name composed using specified encoding regardless of zip file properties.

using (FileStream fs = File.OpenRead("archive.zip"))
{      
    using (var archive = new Archive(fs, new ArchiveLoadOptions() { Encoding = System.Text.Encoding.GetEncoding(932) }))
    {
        string name = archive.Entries[0].Name;
    }    
}

EntryExtractionProgressed

Gets or sets the delegate invoked when some bytes have been extracted.

public EventHandler<progresscanceleventargs> EntryExtractionProgressed { get; set; }

Property Value

EventHandler < ProgressCancelEventArgs &gt;

Examples

Track the progress of an entry extraction.

var archive = new Archive("archive.zip", 
new ArchiveLoadOptions() { EntryExtractionProgressed = (s, e) =&gt; { int percent = (int)((100 * e.ProceededBytes) / ((ArchiveEntry)s).UncompressedSize); } })

Cancel an entry extraction after a certain time.

Stopwatch watch = Stopwatch.StartNew();
using (Archive a = new Archive("big.zip", new ArchiveLoadOptions() {
    EntryExtractionProgressed = (s, e) =&gt; { if (watch.ElapsedMilliseconds &gt; 1000) e.Cancel = true; } }))
{
    a.Entries[0].Extract("first.bin");
}

Remarks

Event sender is the Aspose.Zip.ArchiveEntry instance which extraction is progressed.

EntryListed

Gets or sets the delegate invoked when an entry listed within table of content.

public EventHandler<entryeventargs> EntryListed { get; set; }

Property Value

EventHandler < EntryEventArgs &gt;

Examples

var archive = new Archive("archive.zip", new ArchiveLoadOptions() { EntryListed = (s, e) =&gt; { Console.WriteLine(e.Entry.Name); } });

SkipChecksumVerification

Get or set a value indicating whether checksum verification of ZIP entries be skipped and mismatch ignored. Default is false.

public bool SkipChecksumVerification { get; set; }

Property Value

bool

 English