Skip to content

tarfile.open() does not forward keyword arguments to the underlying _Stream object for zstd in stream mode #139821

@beavailable

Description

@beavailable

Bug report

Bug description:

I found the bug when I was browsing the source code, so I just put the source code here:

    @classmethod
    def open(cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE, **kwargs):
        # irrevalent code...
        elif "|" in mode:
            # irrevalent code...
            compresslevel = kwargs.pop("compresslevel", 6)
            preset = kwargs.pop("preset", None)
            stream = _Stream(name, filemode, comptype, fileobj, bufsize,
                             compresslevel, preset)
            # irrevalent code...

But the doc says that:

For modes 'w:zst', 'x:zst' and 'w|zst', tarfile.open() accepts the keyword argument level to specify the compression level of the file. The keyword argument options may also be passed, providing advanced Zstandard compression parameters described by CompressionParameter. The keyword argument zstd_dict can be passed to provide a ZstdDict, a Zstandard dictionary used to improve compression of smaller amounts of data.

So there're three keyword arguments: level, options and zstd_dict that need to pass to _Stream constructor, and the constructor needs to change to accept these keyword arguments.

I'll open a PR to fix this soon.

CPython versions tested on:

3.14

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions