Skip to content

gh-51067: add ZipInfo.remove() #103033

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

danny0838
Copy link

@danny0838 danny0838 commented Mar 25, 2023

This is a revision of #19358 (for issue #51067) as the original author seems not keeping working.

Notable changes:


@ghost
Copy link

ghost commented Mar 25, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@danny0838 danny0838 force-pushed the gh-51067 branch 2 times, most recently from b48566e to 76722fa Compare March 25, 2023 15:21
@barneygale
Copy link
Contributor

Automatically compacting the .zip file seems like overkill. Suggestion: split this into two methods:

  • ZipInfo.remove() removes the record for the file, and by default zeroes out its data.
  • ZipFile.repack() reclaims free space.

The latter method is dangerous for self-extracting .zip files, which have an executable header before the the zip data begins. That header would be stripped out, I think.

@barneygale
Copy link
Contributor

barneygale commented Mar 30, 2023

Also, please don't force-push to an open PR. It makes it harder for reviewers to follow changes! Thanks

@arhadthedev arhadthedev added the stdlib Python modules in the Lib dir label Mar 30, 2023
bpepple added a commit to Metron-Project/darkseid that referenced this pull request Aug 31, 2024
bpepple added a commit to Metron-Project/darkseid that referenced this pull request Aug 31, 2024
* Add remove method to ZipFile

Refer to: python/cpython#103033

* Make use of `ZipFileWithRemove`
Removing a member in an archive may involve a move of many internal data
records, which can be I/O intensive for a large ZIP file.

.. versionadded:: 3.12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. versionadded:: 3.12
.. versionadded:: next

Comment on lines +1712 to +1713
raise KeyError(
'There is no item %r in the archive' % zinfo_or_arcname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise KeyError(
'There is no item %r in the archive' % zinfo_or_arcname)
raise KeyError(f'There is no item {zinfo:r} in the archive')

Comment on lines +1793 to +1794
for i in range(len(filelist)):
info = filelist[i]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for i in range(len(filelist)):
info = filelist[i]
for i, info in enumerate(filelist):

no ❔

@merwok merwok added the type-feature A feature request or enhancement label Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

5 participants