Skip to content

Conversation

@iremyux
Copy link
Contributor

@iremyux iremyux commented Jan 21, 2026

This PR adds new overloads to TarFile.CreateFromDirectory and TarFile.CreateFromDirectoryAsync that accept a TarEntryFormat parameter, allowing users to specify the tar archive format when creating archives from directories. Currently, TarFile.CreateFromDirectory always creates archives using TarEntryFormat.Pax.

API Changes

namespace System.Formats.Tar;

public static partial class TarFile
{
    // New overloads:
    public static void CreateFromDirectory(string sourceDirectoryName, Stream destination, bool includeBaseDirectory, TarEntryFormat format);
    public static void CreateFromDirectory(string sourceDirectoryName, string destinationFileName, bool includeBaseDirectory, TarEntryFormat format);
    public static Task CreateFromDirectoryAsync(string sourceDirectoryName, Stream destination, bool includeBaseDirectory, TarEntryFormat format, CancellationToken cancellationToken = default);
    public static Task CreateFromDirectoryAsync(string sourceDirectoryName, string destinationFileName, bool includeBaseDirectory, TarEntryFormat format, CancellationToken cancellationToken = default);
}

Implements #121819

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-formats-tar
See info in area-owners.md if you want to be subscribed.

@iremyux iremyux marked this pull request as ready for review January 21, 2026 11:12
@iremyux iremyux requested review from a team and Copilot January 21, 2026 11:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds new overloads to TarFile.CreateFromDirectory and TarFile.CreateFromDirectoryAsync methods that accept a TarEntryFormat parameter, allowing users to specify the tar archive format (V7, Ustar, Pax, or Gnu) when creating archives from directories. Previously, these methods always used the Pax format by default.

Changes:

  • Added four new public API overloads with TarEntryFormat parameter
  • Modified existing overloads to delegate to new overloads with TarEntryFormat.Pax as default
  • Added ValidateTarEntryFormat helper method to validate format parameter
  • Added comprehensive test coverage for the new overloads

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/libraries/System.Formats.Tar/ref/System.Formats.Tar.cs Added four new public API signatures for CreateFromDirectory and CreateFromDirectoryAsync with TarEntryFormat parameter
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarFile.cs Implemented new overloads, added format validation, updated internal methods to accept format parameter, modified existing methods to delegate with Pax default
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectory.Stream.Tests.cs Added tests for invalid format validation and format-specific archive creation
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectory.File.Tests.cs Added tests for invalid format validation and format-specific archive creation
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectoryAsync.Stream.Tests.cs Added async tests for invalid format validation and format-specific archive creation
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectoryAsync.File.Tests.cs Added async tests for invalid format validation and format-specific archive creation

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Copy link
Member

@alinpahontu2912 alinpahontu2912 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, sourceDirectoryName));
}

ValidateTarEntryFormat(format);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this validation necessary, or will it be handled implicitly by the underlying TarWriter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, TarWriter already validates the format, I added so it fails early. But yes, it is redundant

@iremyux
Copy link
Contributor Author

iremyux commented Jan 23, 2026

Closing since it's a duplicate of #123407

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants