How to Merge several TAR.XZ files to a single TAR.BZ2 using C#

In order to merge several archives into one, we’ll use

Aspose.ZIP for .NET

API which is a feature-rich, powerful and easy to use archive manipulation API for C# platform. Open

NuGet

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.XZ archives to one TAR.BZ2 via C#

Combine several archives to another single one consist of following steps:

  1. Define full path to archives.
  2. Prepare an empty folder that will be used as intermediate storage.
  3. Using the Archive objects, extract their content to intermediate folder using its ExtractToDirectory method.
  4. Compose destination archive of desired format, supplying intermediate storage as their source.
  5. 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.XZ archives to TAR.BZ2 - C#


     string intermediateStorage = "storage";
                DirectoryInfo stored = Directory.CreateDirectory(intermediateStorage);
                using (TarArchive source1 = TarArchive.FromXz("source1.tar.xz"))
                {
                    source1.ExtractToDirectory(intermediateStorage);
                }

                using (TarArchive source2 = TarArchive.FromXz("source2.tar.xz"))
                {
                    source2.ExtractToDirectory(intermediateStorage);
                }

                using (TarArchive merged = new TarArchive())
                {
                    merged.CreateEntries(stored, false);
                    using (Bzip2Archive bzip2Archive = new Bzip2Archive())
                    {
                        bzip2Archive.SetSource(merged);
                        bzip2Archive.Save("merged.tar.bz2");
                    }
                }

                stored.Delete(true);
  • Free App to Merge TAR.XZ

    Check our live demos for TAR.XZ merger with following benefits.

      No need to download or setup anything.
      No need to write any code.
      Just upload your TAR.XZ archives and hit the "Merge" button.
      You will instantly get the download link for combined TAR.BZ2 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.XZ into many other file formats including few listed below.

    TAR.XZ TO ZIP (Zipped (compressed) Files)
    TAR.XZ TO 7ZIP (7zip Archive)
    TAR.XZ TO TAR.BZ2 (Burrows–Wheeler Compressor)
    TAR.XZ TO CPIO (Copy In, Copy Out Archive)
    TAR.XZ TO TAR.GZ (Streaming Deflate Compressor)
    TAR.XZ TO TAR.LZ (LZMA Multi-Block Compressed Data)
    TAR.XZ TO TAR (Tape Archive)
    TAR.XZ TO TAR.XZ (Container for Compressed Streams)
    TAR.XZ TO TAR.Z (LZW Compressor)