Working with Tar Archive

Learn about the .tar file format, providing APIs for handling tar archives, and working with individual entries in the tar archive.

The .tar files

A file with the extension .tar has been created using the Unix-based archival application tar. A file with the extension .tar.gz has been created using tar and then compressed using the GZIP compression algorithm.

System.Formats.Tar assembly

.NET 7 introduces the System.Formats.Tar assembly, which has APIs for reading, writing, archiving, and extracting tar archives. The TarFile class has static public members, as shown in the following table:

Member

Description

CreateFromDirectory and CreateFromDirectoryAsync

Create a tar stream containing all the filesystem entries from the specified directory.

ExtractToDirectory and ExtractToDirectoryAsync

Extracts the contents of a stream that represents a tar archive into the specified directory.

DefaultCapacity

Windows’ MAX_PATH (260) is used as an arbitrary default capacity.

...