Skip to content

zipfile.ZipInfo._compresslevel should be public. #113971

Closed

Description

@gpshead

Feature or enhancement

Proposal:

Today people pass ZipInfo instances into APIs that accept them such as ZipFile.writestr() in order to control how individual items are put into a zip archive as such:

    zip_info = zipfile.ZipInfo(filename=filename, date_time=desired_timestamp)
    zip_info.compress_type = this_files_compress_type
    # This attribute is sadly not public; manual creation of ZipInfo objects
    # is uncommon.  Without this we cannot write compressed files with our
    # own overridden info.
    zip_info._compresslevel = this_files_compress_level  # pylint: disable=protected-access
    zip_info.external_attr = desired_permissions
    zip_file.writestr(zip_info, data)

There is no reason for ._compresslevel to be protected with an _. We should make it public as it is useful.

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

Activity

  1. self-assigned this
    on Jan 12, 2024
  2. gpshead commented on Jan 12, 2024

    @gpshead
    MemberAuthor

    In general I'd like to expand upon the ability for ZipFile writing APIs to take a ZipInfo instance so making ZipInfo easier to use while retaining compatibility helps. This is one simple little part of that.

    #113925 expands write to accept a ZipInfo. (Even if we don't decide to accept that PR's precompressed= feature, keeping the ability to pass ZipInfo and file objects in more places as implemented there would be good - We've got code at work that'd be more efficient that way)

  3. moved this to In Progress in Zipfile issues 📦on Jan 12, 2024
  4. moved this from In Progress to Done in Zipfile issues 📦on Jan 12, 2024
  5. added a commit that references this issue on Jan 12, 2024
  6. added a commit that references this issue on Jan 22, 2024
  7. added a commit that references this issue on Feb 11, 2024
  8. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.13only security fixestype-featureA feature request or enhancement

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions