XAR extraction
Contents
[
Hide
Show
]Overview
Xar is popular Mac OS archiving format. You can extract such an archive with Aspose.Zip similarly as other archives.
Aspose.Zip can extract XAR entries compressed with gzip, bzip2, lzma.
Extract an Entry
Following sample extracts entries of the archive one by one.
Steps: Extracting Entries from a XAR Archive in C#
- Check if the directory C:\\extracted exists; create it if necessary.
- Open the XAR archive using XarArchive(“data.xar”).
- Iterate over each entry in the archive.
- If the entry is a file, extract it to C:\\extracted.
- 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
Following sample extracts all content to the directory.
1 using (XarArchive xarArchive = new XarArchive("data.xar"))
2 {
3 xarArchive.ExtractToDirectory("data");
4 }