Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active January 6, 2022 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/7d70833d03a4a84b810f2b641c30547d to your computer and use it in GitHub Desktop.
Save aspose-com-gists/7d70833d03a4a84b810f2b641c30547d to your computer and use it in GitHub Desktop.
Create TAR.GZ and TAR.XZ Files in C# .NET
// Create TAR archive
using (var archive = new TarArchive())
{
// Add files to archive
archive.CreateEntry("text.txt", @"D:\texts\article.txt");
archive.CreateEntry("picture.png", @"D:\Picture\photo.png");
// Compress TAR into tar.gz file
archive.SaveGzipped("result.tar.gz");
}
// Create a tar.xz file
using (FileStream xzFile = File.Open("archive.tar.xz", FileMode.Create))
{
// Create TAR archive
using (var archive = new TarArchive())
{
// Add files to archive
archive.CreateEntry("text.txt", @"D:\texts\article.txt");
archive.CreateEntry("picture.png", @"D:\Picture\photo.png");
// Compress TAR into tar.xz file
archive.SaveXzCompressed(xzFile);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment