Skip to content

[API Proposal]: Add APIs to System.IO.Compression that can compressed tar archives like tar.gz #70517

Open
@carlossanlop

Description

@carlossanlop

The APIs we added in System.Formats.Tar are meant for handling the tar format only. No compression handling was added there.

Currently, to handle compressed tar.gz files with those APIs, we can use these two methods:

We can extract the whole archive in one call:

using FileStream compressedStream = File.OpenRead("/home/dotnet/SourceDirectory/compressed.tar.gz");
using GZipStream decompressor = new(compressedStream, CompressionMode.Decompress);
TarFile.ExtractToDirectory(source: decompressor, destinationDirectoryName: "/home/dotnet/DestinationDirectory/", overwriteFiles: false);

Or we can iterate through each individual entry and decide what to do with each:

using FileStream compressedStream = File.OpenRead(@"D:\SourceDirectory\compressed.tar.gz");
using GZipStream decompressor = new(compressedStream, CompressionMode.Decompress);
using TarReader reader = new(decompressor, leaveOpen: true);
TarEntry? entry;

while ((entry = GetNextEntry(copyData: true)) != null)
{
    Console.WriteLine($"Entry type: {entry.EntryType}, entry name: {entry.Name}");
}

If we want to add APIs that can handle archives compressed with gzip (or any compression algorithm), we should add them to System.IO.Compression. I am opening this issue to initiate the discussion.

Note: We have an open issue that is trying to standardize the way we use all our compression algorithms: Standardize pattern for exposing advanced configuration for compression streams. It's possible this proposal depends on solving that one first.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions