Working with XZ Archives

Overview

XZ archive is common in Linux. It uses LZMA2 algorithm. Aspose.ZIP for .NET API lets work with creating and managing XZ archives in your applications without the need of any other 3rd party applications. Aspose.ZIP API provides  XzArchive class to work with such archives. This class provides basic methods to perform operations on archives.

Compress A File

The following code example shows how to compress a file using XzArchive instance.

 1    using (FileStream xzFile = File.Open("data.bin.xz", FileMode.Create))
 2    {
 3        using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
 4        {
 5            using (var archive = new XzArchive(Aspose.Zip.Xz.Settings.XzArchiveSettings.FastestSpeed))
 6            {
 7                archive.SetSource(source);
 8                archive.Save(xzFile);
 9            }
10        }
11    }

Open XZ Archive

The following simple code example shows how to open a XZ archive.

1    using (var archive = new XzArchive("data.bin.xz"))
2    {
3        archive.Extract("data.bin");
4    }

Choosing Checksum Calculation Method

XZ archive allows to choose data integrity calculation from CRC32, CRC64, SHA-256 or omit it. Aspose.Zip implements 3 of such methods: XzCheckType.None, XzCheckType.Crc32, XzCheckType.Crc64. Default is CRC32.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.