-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
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
base: main
Are you sure you want to change the base?
gh-51067: add ZipInfo.remove() #103033
Conversation
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
b48566e
to
76722fa
Compare
Automatically compacting the
The latter method is dangerous for self-extracting |
Also, please don't force-push to an open PR. It makes it harder for reviewers to follow changes! Thanks |
* 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. versionadded:: 3.12 | |
.. versionadded:: next |
raise KeyError( | ||
'There is no item %r in the archive' % zinfo_or_arcname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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') |
for i in range(len(filelist)): | ||
info = filelist[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for i in range(len(filelist)): | |
info = filelist[i] | |
for i, info in enumerate(filelist): |
no ❔
This is a revision of #19358 (for issue #51067) as the original author seems not keeping working.
Notable changes:
Added docs and tests.
Support mode 'w' and 'x', as noted by remove/delete method for zipfile/tarfile objects #51067 (comment)
Support removing multiple members and removing non-physically with the internal
_remove_members
method, as they may be used by some interested people, as noted by remove/delete method for zipfile/tarfile objects #51067 (comment) and remove/delete method for zipfile/tarfile objects #51067 (comment).They are not currently introduced in the public
remove
API, as it would involve more complicated changes to the public APIs (e.g. introducing error handling for multiple members, and a extra method that purges stale data by non-physical removing) and other ZipFile related APIs do not support similar operations.Move physical data in chunks, to prevent a memory issue for large files.
Fixed a flaw of the previous implementation that
self.NameToInfo
gets a missing key when removing one of duplicated arcnames.