Skip to content

python -m gzip ignores --fast and --best for file arguments #161086

Closed

Description

@gpshead

Bug report

Bug description:

python -m gzip --fast FILE and python -m gzip --best FILE compress at the default level. main() passes compresslevel to GzipFile only when reading stdin; the file-argument branch calls gzip.open(arg + ".gz", "wb") without it.

head -c 3000000 /dev/urandom | base64 > data
for opt in --fast --best; do cp data data$opt; python -m gzip $opt data$opt; done
ls -l data--fast.gz data--best.gz   # identical sizes, XFL header byte is 0 in both
python -m gzip --fast < data | wc -c   # differs from --best < data, as expected

Expected --fast and --best to produce different output (and XFL 4 and 2) for files, as they do for stdin. The options were added in gh-79150 (GH-9833), which wired them up only for stdin.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. self-assigned this
    on Nov 1, 2026
  2. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 1, 2026
  3. added a commit that references this issue on Nov 1, 2026
  4. added 2 commits that reference this issue on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions