ALZ extraction

Overview

Aspose.Zip for .NET lets you read and extract ALZ archives with the Aspose.Zip.Alz namespace. Use AlzArchive to open an archive from a file or a readable, seekable stream. You can list its entries, unpack the complete archive, or extract an individual file to a path or stream.

ALZ support is extraction-only. The API does not provide methods for creating or updating ALZ archives. It can extract entries that are stored without compression or compressed with Deflate.

Extract the Whole Archive

Call ExtractToDirectory to unpack all files and directories. The destination directory is created when it does not already exist.

1    using Aspose.Zip.Alz;
2
3    using (AlzArchive archive = new AlzArchive("archive.alz"))
4    {
5        archive.ExtractToDirectory(@"C:\extracted");
6    }

Inspect and Extract an Individual Entry

The Entries collection contains AlzEntry objects. Each entry exposes its name, compressed and uncompressed sizes, and whether it represents a directory. Extract a file entry to a destination path with Extract.

 1    using Aspose.Zip.Alz;
 2    using System;
 3    using System.Linq;
 4
 5    using (AlzArchive archive = new AlzArchive("archive.alz"))
 6    {
 7        foreach (AlzEntry entry in archive.Entries)
 8        {
 9            Console.WriteLine($"{entry.Name}: {entry.UncompressedSize} bytes");
10        }
11
12        AlzEntry firstFile = archive.Entries.First(entry => !entry.IsDirectory);
13        firstFile.Extract(@"C:\extracted\first.bin");
14    }

To process an entry in memory or send it to another API, use Open to obtain a stream of decompressed data. Do not call Open or extract to a stream for a directory entry.

 1    using Aspose.Zip.Alz;
 2    using System.IO;
 3    using System.Linq;
 4
 5    using (AlzArchive archive = new AlzArchive("archive.alz"))
 6    {
 7        AlzEntry entry = archive.Entries.First(item => !item.IsDirectory);
 8
 9        using (Stream source = entry.Open())
10        using (FileStream destination = File.Create(@"C:\extracted\first.bin"))
11        {
12            source.CopyTo(destination);
13        }
14    }

Extract Password-protected Entries

ALZ archives can contain encrypted entries. For a whole-archive extraction, provide the password in AlzArchiveLoadOptions when opening the archive.

 1    using Aspose.Zip.Alz;
 2
 3    AlzArchiveLoadOptions options = new AlzArchiveLoadOptions()
 4    {
 5        DecryptionPassword = "p@s$w0rd"
 6    };
 7
 8    using (AlzArchive archive = new AlzArchive("protected.alz", options))
 9    {
10        archive.ExtractToDirectory(@"C:\extracted");
11    }

For a selected entry, pass the optional password directly to Extract or Open.

1    using Aspose.Zip.Alz;
2    using System.Linq;
3
4    using (AlzArchive archive = new AlzArchive("protected.alz"))
5    {
6        AlzEntry entry = archive.Entries.First(item => !item.IsDirectory);
7        entry.Extract(@"C:\extracted\first.bin", "p@s$w0rd");
8    }

Open an Archive from a Stream

The source stream must support both reading and seeking. This is useful when the ALZ file comes from storage, a database, or another component rather than a file name.

1    using Aspose.Zip.Alz;
2    using System.IO;
3
4    using (FileStream source = File.OpenRead("archive.alz"))
5    using (AlzArchive archive = new AlzArchive(source))
6    {
7        archive.ExtractToDirectory(@"C:\extracted");
8    }

Handle Entry-name Encoding

By default, Aspose.Zip interprets ALZ entry names with Korean Windows code page 949 (CP949), the encoding historically used by ALZ. If an archive uses a different encoding, set the Encoding property before opening it.

 1    using Aspose.Zip.Alz;
 2    using System.Text;
 3
 4    AlzArchiveLoadOptions options = new AlzArchiveLoadOptions()
 5    {
 6        Encoding = Encoding.UTF8
 7    };
 8
 9    using (AlzArchive archive = new AlzArchive("utf8-names.alz", options))
10    {
11        archive.ExtractToDirectory(@"C:\extracted");
12    }

Cancel Extraction and Verify Data

Set CancellationToken in AlzArchiveLoadOptions to stop a long-running extraction. ExtractToDirectory, Extract, and Open throw OperationCanceledException when cancellation is requested.

 1    using Aspose.Zip.Alz;
 2    using System;
 3    using System.Threading;
 4
 5    using (CancellationTokenSource cts = new CancellationTokenSource())
 6    {
 7        cts.CancelAfter(TimeSpan.FromSeconds(60));
 8
 9        AlzArchiveLoadOptions options = new AlzArchiveLoadOptions()
10        {
11            CancellationToken = cts.Token
12        };
13
14        try
15        {
16            using (AlzArchive archive = new AlzArchive("large.alz", options))
17            {
18                archive.ExtractToDirectory(@"C:\extracted");
19            }
20        }
21        catch (OperationCanceledException)
22        {
23            Console.WriteLine("Extraction was canceled.");
24        }
25    }

Checksum verification is enabled by default. Leave SkipChecksumVerification set to false to detect corrupted entry data. A wrong password or corrupt archive causes InvalidDataException during extraction.

ALZ Support Summary