XZ is one of the widely used compression formats. It provides features that optimize business data storage and ensure reliable data transfer. In this guide, we will run through how to achieve XZ compression and extraction in C#. Aspose.ZIP for .NET is an enterprise-level SDK aimed at working with archive file formats. The implementation is quite simple, and you can modify the code samples as per your needs. In addition to XZ, we will also see how to compress and decompress ZST archives programmatically.

SDK Installation

In order to install Aspose.ZIP for .NET, run the following command:

Install-Package Aspose.Zip

You can also download the SDK files or install via the NuGet package manager.

XZ Compression and Extraction in C#

Now, let’s head straight to the implementation phase. You may follow the steps given below:

  • Create an object of the XzArchive class.
  • Invoke the SetSource method to define the content for compression.
  • The Save method will save the XZ archive to the destination file provided.

The following code sample creates an XZ file: Output:

xz-compression

Similarly, if you want to decompress an XZ file, you can follow the code snippet given below:

Output:

xz-compression

Compress ZST File using Aspose.ZIP for .NET

As started earlier in this blog post, Aspose.ZIP for .NET offers features to work with archive file formats. So, in this section, we will see how to compress and decompress ZST files in .NET:

For ZST compression, please follow the code sample given below You may extract ZST files using the following code sample:

Get a Free License

Get a free temporary license to try this compression SDK beyond evaluation limitations.

Conclusion

This brings us to the end of this blog post. We have gone through how to achieve XZ compression and extraction in C# programmatically. In addition, we also covered how you can compress and decompress ZST archives using Aspose.ZIP for .NET. Further, we will continue to write on useful topics. Meanwhile, you can explore documentation and API refs. You may visit the GitHub repo to see code examples.

Also, you may ask your questions on our support forum.

FAQs

Q: How much does XZ compress?

Using Aspose.ZIP for .NET, XZ can typically compress files by 2× to 5×, depending on the data type.

Q: What is the XZ compression format?

The XZ compression format is a lossless data compression format based on the LZMA2 algorithm. It is designed to achieve very high compression ratios while efficiently handling large files.

Q: Is XZ lossless?

Yes, XZ is a lossless compression format, meaning it reduces file size without losing any data, and the original file can be fully restored after decompression.

Q: What is the ZST format?

The ZST format (commonly known as Zstandard or ZSTD) is a fast, lossless compression algorithm and file format.

Q: How to extract a .ZST file?

In .NET, you can extract a ZST file easily using Aspose.ZIP for .NET. Please visit this link to see the code sample.

Explore