How to Merge several TAR.BZ2 files to a single ZIP using C#
In order to merge several archives into one, we’ll use
API which is a feature-rich, powerful and easy to use archive manipulation 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 Merge TAR.BZ2 archives to one ZIP via C#
Combine several archives to another single one consist of following steps:
- Define full path to archives.
- Prepare an empty folder that will be used as intermediate storage.
- Using the Archive objects, extract their content to intermediate folder using its ExtractToDirectory method.
- Compose destination archive of desired format, supplying intermediate storage as their source.
- You will get merged archive having overall content of those archives.
System Requirements
Before running the merger 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.
Merge two TAR.BZ2 archives to ZIP - C#
string intermediateStorage = "storage";
DirectoryInfo stored = Directory.CreateDirectory(intermediateStorage);
using (MemoryStream ms = new MemoryStream())
{
using (Bzip2Archive source1 = new Bzip2Archive("source1.tar.bz2"))
source1.Extract(ms);
ms.Seek(0, SeekOrigin.Begin);
using (TarArchive tar1 = new TarArchive(ms))
tar1.ExtractToDirectory(intermediateStorage);
}
using (MemoryStream ms = new MemoryStream())
{
using (Bzip2Archive source2 = new Bzip2Archive("source2.tar.bz2"))
source2.Extract(ms);
ms.Seek(0, SeekOrigin.Begin);
using (TarArchive tar2 = new TarArchive(ms))
tar2.ExtractToDirectory(intermediateStorage);
}
using (Archive merged = new Archive())
{
merged.CreateEntries(stored, false);
merged.Save("merged8.zip");
}
stored.Delete(true);
Free App to Merge TAR.BZ2
Check our live demos for TAR.BZ2 merger with following benefits.
No need to download or setup anything.
No need to write any code.
Just upload your TAR.BZ2 archives and hit the "Merge" button.
You will instantly get the download link for combined ZIP file.
A reliable Aspose.ZIP Library that can compress, extract, encrypt, decrypt, convert and merge archives. Aspose.ZIP for .NET API allows to manipulate various archive types without without going into the underlying complexity of the compress file formats with minimum coding efforts.
Other Supported Merge archives
You can also combine TAR.BZ2 into many other file formats including few listed below.
TAR.BZ2 TO ZIP (Zipped (compressed) Files)
TAR.BZ2 TO 7ZIP (7zip Archive)
TAR.BZ2 TO TAR.BZ2 (Burrows–Wheeler Compressor)
TAR.BZ2 TO CPIO (Copy In, Copy Out Archive)
TAR.BZ2 TO TAR.GZ (Streaming Deflate Compressor)
TAR.BZ2 TO TAR.LZ (LZMA Multi-Block Compressed Data)
TAR.BZ2 TO TAR (Tape Archive)
TAR.BZ2 TO TAR.XZ (Container for Compressed Streams)
TAR.BZ2 TO TAR.Z (LZW Compressor)