Skip to content

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

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:

usingFileStreamcompressedStream=File.OpenRead("/home/dotnet/SourceDirectory/compressed.tar.gz");usingGZipStreamdecompressor=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:

usingFileStreamcompressedStream=File.OpenRead(@"D:\SourceDirectory\compressed.tar.gz");usingGZipStreamdecompressor=new(compressedStream,CompressionMode.Decompress);usingTarReaderreader=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

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions