Working with XZ Archives
Overview
XZ archives are commonly used on Linux systems and utilize LZMA2 algorithm. Aspose.ZIP for .NET API enables you to create and manage XZ archives in your applications without requiring third-party tools. The 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 demonstrates 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 demonstrates 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 archives allow data integrity verification using CRC32, CRC64, SHA-256, or none.
Aspose.ZIP supports three options: XzCheckType.None, XzCheckType.Crc32, and XzCheckType.Crc64. The default setting is CRC32.