Open or create TAR files in C# with Aspose.ZIP
Tags: tar, zip, compression, csharp
Published: 2021-04-25 14:11:51

## Prerequisite – C# ZIP Library
[Aspose.ZIP for .NET](https://products.aspose.com/zip/net) is a powerful and easy-to-use API for zipping or unzipping files and folders within .NET applications. It supports all the most popular ZIP formats and provides AES encryption techniques to encrypt the files in ZIP archives. You can install the API from [NuGet](https://www.nuget.org/packages/Aspose.ZIP) or download its binaries from the [Aspose Downloads](https://downloads.aspose.com/zip/net) section.

## How to create a TAR in .NET
The next part of the code demonstrates the creation of a new TAR archive:
```
using (var archive = new TarArchive())
{
    archive.CreateEntry("alice29.txt", File.OpenRead( "alice29.txt"));
    archive.Save("Archive.tar");
}
```
That's all, after 3 lines of code the TAR archive has been saved to the disk!

## Other TAR standards.
There are several different TAR standards: [ustar](https://en.wikipedia.org/wiki/Tar_(computing)#UStar_format), [GNU tar](https://en.wikipedia.org/wiki/Tar_(computing)#Key_implementations), [pax](https://ru.wikipedia.org/wiki/Pax_(Unix)) and V7. **Ustar** format is the default implementation for the most Windows applications, while **GNU tar** is the default for Linux command shell. Aspose.ZIP currently supports **ustar** and **GNU tar**. The Aspose.ZIP library creates archives in **ustar** format by default. To create a **GNU tar** archive the TAR format must be explicitly specified:
```
using (var archive = new TarArchive())
{
    archive.CreateEntry("alice29.txt", File.OpenRead( "alice29.txt"));
    archive.Save("Archive.tar", TarFormat.Gnu);
}
```
## Ustar vs GNU Tar. What's the difference?
In what cases it’s better to use **GNU tar** than **ustar**? 
1. **Ustar** has some limitations compared to **GNU tar**, for example, **ustar** doesn’t support entries with names more than 100 characters, the total size of the archive can’t be more than 8 Gb. If created tarball isn’t fit for these restrictions Aspose.ZIP will save the archive in **GNU tar** format even without passing **TarFormat.Gnu** in **Save** method.
2. Another difference between standards is that **GNU tar** supports saving [sparse files](https://wiki.archlinux.org/index.php/sparse_file) in the archive.

## Compress TAR using GZip.
Tarball can be compressed to GZip using Aspose.ZIP:
```
using (FileStream tarGzStream = File.OpenWrite("Archive.tar.gz"))
{
    using (var archive = new TarArchive())
    {
        archive.CreateEntry("alice29.txt", File.OpenRead("alice29.txt"));
        archive.SaveGzipped(tarGzStream);
    }
}
```
##Learn more about Aspose.ZIP for .NET
Aspose.ZIP provides features to work with many other zip standards. Written totally on managed code Aspose.ZIP will be a good choice for applications that run on different OS.
Explore more about our C# ZIP API using the following resources:
* [Documentation](https://docs.aspose.com/display/zipnet/Getting+Started)
* [Source code examples](https://github.com/aspose-zip/Aspose.ZIP-for-.NET)

Check what Aspose.ZIP is capable of with our free web-apps that are completely based on Aspose.ZIP for .NET:
* [Create TAR archive online](https://products.aspose.app/zip/zip-file/tar)
* [Convert TAR to ZIP online](https://products.aspose.app/zip/conversion/tar-to-zip)
* [Merge TAR archives online](https://products.aspose.app/zip/merger)