How to Convert RAR to TAR.XZ Using C#
In order to convert RAR to TAR.XZ, we’ll use
API which is a feature-rich, powerful and easy to use archive conversion API for C# platform. Open
package manager, search for Aspose.ZIP and install. You may also use the following command from the Package Manager Console.
Package Manager Console Command
PM> Install-Package Aspose.Zip
Steps to Convert RAR to TAR.XZ via C#
Convertation from one archive format to another consist of following steps:
- Extract archive to intermediate storage
- Compress extracted data to desired format
System Requirements
Before running the conversion example code, make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with .NET Framework, Mono and COM Interop.
- Development environment like Microsoft Visual Studio.
- Aspose.ZIP for .NET DLL referenced in your project.
Sample code to convert from RAR to TAR.XZ
Code to convert to various formats from RAR. The RAR archive contains several records, and the formats GZ, LZ, Z, XZ, BZ2 compress one source. Therefore compression in these formats occurs with packing at first in TAR archive that is typical for Linux
Convert from RAR to TAR.XZ - C#
using (TarArchive tarArchive = new TarArchive())
{
using (RarArchive rar = new RarArchive(@"archive.rar"))
{
for (int i = 0; i < rar.Entries.Count; i++)
{
if (!rar.Entries[i].IsDirectory)
{
var ms = new MemoryStream();
rar.Entries[i].Extract(ms);
ms.Seek(0, SeekOrigin.Begin);
tarArchive.CreateEntry(rar.Entries[i].Name, ms);
}
else
tarArchive.CreateEntry(rar.Entries[i].Name + "/", Stream.Null);
}
}
tarArchive.SaveXzCompressed("output.tar.xz");
}
Free App to Convert RAR to TAR.XZ
Check our live demos for RAR to TAR.XZ conversion with following benefits.
Other Supported Conversions
You can also convert RAR into many other file formats including few listed below.