ZIP is a popular archiving format that is used to compress files and folders. ZIP makes it easier to share multiple files by reducing their size and keeping them into a single file. On the other hand, TAR is a famous Unix-based archiving format that is used to package the files before sharing. In various cases, you have to convert the ZIP archives into TAR format. To achieve this programmatically, this article shows how to convert a ZIP archive to TAR in C#.
C# .NET API to Convert ZIP to TAR
To convert ZIP archives to TAR format, we will use Aspose.ZIP for .NET. The API provides a wide range of features to create and manipulate ZIP, TAR, and other popular archiving formats. You can either download the API’s DLL or install it from NuGet.
PM> Install-Package Aspose.Zip
Convert a ZIP Archive to TAR in C#
The conversion of ZIP to TAR is quite easy using Aspose.ZIP for .NET. Simply, load the ZIP file, transfer its entries to a TAR archive and save the TAR archive to your desired location. The following are the steps to convert a ZIP archive to TAR in C#.
- Load the ZIP file using Archive class.
- Create an object of TarArchive class for TAR archive.
- Access each ArchiveEntry in the ZIP using Archive.Entries collection.
- For each entry in ZIP archive, perform the following steps:
- Copy entry into a MemoryStream object using ArchiveEntry.Open().CopyTo(MemoryStream) method.
- Transfer entry to TAR archive using TarArchive.CreateEntry(String, MemoryStream) method.
- Finally, save the TAR archive to your desired location using TarArchive.Save(String) method.
The following code sample shows how to convert a ZIP archive to TAR format in .NET applications.
Get a Free API License
You can get a free temporary license to use Aspose.ZIP for .NET without evaluation limitations.
The conversion of ZIP archives to TAR format is often needed before sharing the files over the internet. Therefore, in this article, you have learned how to convert a ZIP archive to TAR programmatically in C#. You can simply install Aspose.ZIP for .NET and embed the provided code to perform ZIP to TAR conversion from within your .NET applications. In addition, you can visit documentation to explore more about Aspose.ZIP for .NET. Moreover, you can share your queries with us via our forum.