XAR extraction

Overview

Xar s a popular archiving format for macOS. You can extract XAR archives with Aspose.Zip using methods similar to those for other archive formats.

Aspose.Zip supports extraction of XAR entries compressed with Gzip, Bzip2, and LZMA.

Extract an Entry

The following sample demonstrates how to extract entries from a XAR archive one by one.

Steps: Extracting Entries from a XAR Archive in C#

  1. Check if the directory C:\extracted exists; create it if necessary.
  2. Open the XAR archive using XarArchive(“data.xar”).
  3. Iterate over each entry in the archive.
  4. If the entry is a file, extract it to C:\extracted.
  5. If the entry is a directory, create the corresponding directory in C:\extracted.
 1    if (!Directory.Exists("C:\\extracted"))
 2    {
 3        Directory.CreateDirectory("C:\\extracted");
 4    }
 5
 6    using(XarArchive xarArchive =  new XarArchive("data.xar"))
 7    {
 8        foreach (XarEntry entry in xarArchive.Entries) 
 9        {
10            if (entry is XarFileEntry xarFileEntry)
11            {
12                var entryPath = Path.Combine("C:\\extracted", entry.FullPath);
13                xarFileEntry.Extract(entryPath);
14            }
15            else if (entry is XarDirectoryEntry)
16            {
17                var entryPath = Path.Combine("C:\\extracted", entry.FullPath);
18                Directory.CreateDirectory(entryPath);
19            }
20        }
21    }

Extract Whole Arcive

This example demonstrates how to extract all contents of a XAR archive to a directory in one step:

1    using (XarArchive xarArchive = new XarArchive("data.xar"))
2    {
3        xarArchive.ExtractToDirectory("data");
4    }

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.