Skip to content

Extract tar.gz, tag.xz

Alexander edited this page Jan 15, 2020 · 1 revision

tar.xz is actually two archive files:

  • tar packs all files and folders into one so called tarball file without compression
  • xz does compression

to unpack you need to perform same operations in reverse:

using (ArchiveFile archiveFileXz = new ArchiveFile(@"Linux-5.4.12.tar.xz"))
{
    MemoryStream memoryStream = new MemoryStream();
    archiveFileXz.Entries[0].Extract(memoryStream);

    using (ArchiveFile archiveFileTar = new ArchiveFile(memoryStream, SevenZipFormat.Tar))
    {
        foreach (Entry entry in archiveFileTar.Entries)
        {
            Console.WriteLine(entry.FileName);
        }
    }
}

this code is somewhat inefficient as it creates unpacked file copy in a memory, but it is ok for small files

Clone this wiki locally