ARJ extraction
Overview
ARJ is a classic DOS and Windows archive format that still appears in legacy software packages, utilities, and backups. Aspose.Zip for .NET lets you open an ARJ archive, inspect archive metadata, extract individual entries to a file or stream, extract the whole archive to a directory, and cancel long-running extraction with CancellationToken.
ARJ support is partial. Aspose.ZIP can extract regular non-garbled ARJ entries. Garbled or encrypted ARJ archives are not supported, and entries compressed with ARJ method 4 throw NotImplementedException during extraction.
Inspect Archive Metadata
ARJ archives expose archive-level information such as the archive file name, archive commentary, and the entries collection.
1 using (ArjArchive archive = new ArjArchive("archive.arj"))
2 {
3 Console.WriteLine(archive.Name);
4 Console.WriteLine(archive.Commentary);
5 Console.WriteLine(archive.Entries.Count);
6 }Extract Individual Entries
You can extract an ARJ entry directly to a file path or to a writable stream.
1 using (ArjArchive archive = new ArjArchive("archive.arj"))
2 {
3 archive.Entries[0].Extract("first.bin");
4
5 using (MemoryStream output = new MemoryStream())
6 {
7 archive.Entries[1].Extract(output);
8 }
9 }When ARJ metadata contains file timestamps and DOS or Windows attributes, Aspose.ZIP applies them to the extracted file where the platform allows it.
Extract Whole Archive
If you need the complete contents, extract all entries to a directory in one call.
1 using (ArjArchive archive = new ArjArchive("archive.arj"))
2 {
3 archive.ExtractToDirectory(@"C:\extracted");
4 }Extract a Multi-volume Part
Aspose.ZIP can also open an individual volume from a multi-volume ARJ set and extract the data stored in that specific part.
1 using (ArjArchive archive = new ArjArchive("ALICE_MU.A04"))
2 using (MemoryStream partData = new MemoryStream())
3 {
4 archive.Entries[0].Extract(partData);
5 }Cancel ARJ Extraction
If extraction can take a long time, pass
ArjLoadOptions with a CancellationToken.
1 using (CancellationTokenSource cts = new CancellationTokenSource())
2 {
3 cts.CancelAfter(TimeSpan.FromSeconds(60));
4
5 try
6 {
7 using (ArjArchive archive = new ArjArchive("big.arj",
8 new ArjLoadOptions() { CancellationToken = cts.Token }))
9 {
10 archive.ExtractToDirectory("destination");
11 }
12 }
13 catch (OperationCanceledException)
14 {
15 Console.WriteLine("Extraction was cancelled after 60 seconds.");
16 }
17 }Important Notes
- Opening a garbled or encrypted ARJ archive throws
NotSupportedException. - Extracting an entry compressed with ARJ method 4 throws
NotImplementedException.