Skip to content

Compression level for zipfile #65616

Closed
Closed

Description

@Sworddragon
BPO 21417
Nosy @gpshead, @berkerpeksag, @serhiy-storchaka, @AraHaan, @bbayles
PRs
  • bpo-21417: Compression level for zipfile #5385
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-01-30.06:52:14.039>
    created_at = <Date 2014-05-02.18:00:16.328>
    labels = ['3.7', 'type-feature', 'library']
    title = 'Compression level for zipfile'
    updated_at = <Date 2018-02-26.22:50:36.558>
    user = 'https://bugs.python.org/Sworddragon'

    bugs.python.org fields:

    activity = <Date 2018-02-26.22:50:36.558>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-01-30.06:52:14.039>
    closer = 'gregory.p.smith'
    components = ['Library (Lib)']
    creation = <Date 2014-05-02.18:00:16.328>
    creator = 'Sworddragon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 21417
    keywords = ['patch']
    message_count = 10.0
    messages = ['217770', '245753', '272610', '272611', '272646', '311237', '312883', '312921', '312961', '312968']
    nosy_count = 10.0
    nosy_names = ['gregory.p.smith', 'alanmcintyre', 'Sworddragon', 'fberger', 'berker.peksag', 'jens', 'serhiy.storchaka', 'jfoo', 'Decorater', 'bbayles']
    pr_nums = ['5385']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'commit review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue21417'
    versions = ['Python 3.7']

    Activity

    1. Sworddragon commented on May 2, 2014

      Sworddragonmannequin
      MannequinAuthor

      This is a fork from this ticket: http://bugs.python.org/issue21404

      tarfile has a compression level and seems to get now the missing documentation for it. But there is still a compression level missing for zipfile.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on May 2, 2014
    3. jens commented on Jun 24, 2015

      jensmannequin
      Mannequin

      btw. hacked work-a-round is:

          zlib.Z_DEFAULT_COMPRESSION = 9
    4. jfoo commented on Aug 13, 2016

      jfoomannequin
      Mannequin

      Would compresslevel be a suitable argument? All the backend compressors accept values from 1 to 9 if I'm not mistaken.

    5. AraHaan commented on Aug 13, 2016

      AraHaanmannequin
      Mannequin

      Yes, it would make sence or better yet have a arg that is optional that if not set make it = 9.

    6. jfoo commented on Aug 14, 2016

      jfoomannequin
      Mannequin

      I thought about that, but:

      1. compresslevel=None might make look like no compression was being done at all
      2. The current default is not 9 for all backends
    7. gpshead commented on Jan 30, 2018

      @gpshead
      Member

      New changeset ce237c7 by Gregory P. Smith (Bo Bayles) in branch 'master':
      bpo-21417: Add compresslevel= to the zipfile module (GH-5385)
      ce237c7

    8. serhiy-storchaka commented on Feb 26, 2018

      @serhiy-storchaka
      Member

      I have a concern about the _compresslevel attribute of ZipInfo. Why is it underscored and not documented?

    9. bbayles commented on Feb 26, 2018

      bbaylesmannequin
      Mannequin

      I made a comment about that in the pull request that went unchallenged ([1]), but I'm happy to change it.

      [1] #5385 (review)

    10. gpshead commented on Feb 26, 2018

      @gpshead
      Member

      keeping the conversation in one place, the code review comment was: "I've prefixed this with an underscore because it's not exposed when reading back. ZipInfo has another "private" attribute, _raw_time"

      compresslevel is documented on the public APIs where it appears, I do not believe it needs to be a public attribute within ZipInfo given the above as that is an implementation detail. If we ever find a good reason to make it public in the future we can add a property.

    11. serhiy-storchaka commented on Feb 26, 2018

      @serhiy-storchaka
      Member

      This makes sense to me. Thank you for explanation.

    12. transferred this issue fromon Apr 10, 2022
    13. zborro commented on Nov 4, 2022

      @zborro

      @gpshead so is it a bug or a feature that adding files to archive using ZipInfo completely ignores what compression type and compression level is set in the ZipFile instance?

      In the library code there is:

              # Make sure we have an info object
              if isinstance(name, ZipInfo):
                  # 'name' is already an info object
                  zinfo = name

      So it takes ZipInfo as is. If one wants to set compression level, that private field needs to be set:

      zipinfo._compresslevel = 9

      Or am I missing something here?

    14. lazka commented on Oct 21, 2023

      @lazka
      Contributor

      So it takes ZipInfo as is. If one wants to set compression level, that private field needs to be set:

      zipinfo._compresslevel = 9

      Or am I missing something here?

      @zborro Because I just had a similar issue. You don't need to set the private field, you can pass compresslevel to writestr() instead: zip_file.writestr(zip_info, compress_type=ZIP_DEFLATED, compresslevel=9)

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

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions