Skip to content

tarfile: Support preset argument to tarfile.open(mode="w|xz") #133005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mgorny opened this issue Apr 26, 2025 · 0 comments
Closed

tarfile: Support preset argument to tarfile.open(mode="w|xz") #133005

mgorny opened this issue Apr 26, 2025 · 0 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@mgorny
Copy link
Contributor

mgorny commented Apr 26, 2025

Feature or enhancement

Proposal:

Currently, tarfile.open() doesn't support specifying a compression level / preset when using mode="w|xz". Technically this is documented (via not listing w|xz among the modes supporting either compresslevel or preset argument), it's kinda surprising (to the point of me thinking that w|xz takes compresslevel instead of preset, since the latter threw a TypeError — and then being surprised that the default compression level was used), and quite limiting that you can't set the preset while using stream mode. On top of that, there does not seem to be any technical limitation preventing us from doing that.

I'm working on a pull request to add that option.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@mgorny mgorny added the type-feature A feature request or enhancement label Apr 26, 2025
mgorny added a commit to mgorny/cpython that referenced this issue Apr 26, 2025
Support passing the `preset` option to `tarfile.open` when the file
is open with `mode="w|xz"`.  This aligns the behavior with `"w:xz"`
mode.
mgorny added a commit to mgorny/cpython that referenced this issue Apr 26, 2025
Support passing the `preset` option to `tarfile.open` when the file
is open with `mode="w|xz"`.  This aligns the behavior with `"w:xz"`
mode.
mgorny added a commit to mgorny/cpython that referenced this issue Apr 26, 2025
Support passing the `preset` option to `tarfile.open` when the file
is open with `mode="w|xz"`.  This aligns the behavior with `"w:xz"`
mode.
gpshead pushed a commit that referenced this issue Apr 27, 2025
* gh-133005: Support `tarfile.open(mode="w|xz", preset=...)`

Support passing the `preset` option to `tarfile.open` when the file
is open with `mode="w|xz"`.  This aligns the behavior with `"w:xz"`
mode.

* Also raise an error for `compresslevel` or `preset` with wrong mode

Raise an error if `compresslevel` or `preset` argument is specified
for stream mode with incorrect compression. This should reduce the risk
of mistakes and align the stream modes with regular modes, that raise
an implicit TypeError on unsupported arguments.

* Apply suggestions from code review

Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
@picnixz picnixz added the stdlib Python modules in the Lib dir label Apr 28, 2025
@picnixz picnixz closed this as completed Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
Status: Done
Development

No branches or pull requests

2 participants