-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-51067: add ZipFile.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 ZipFile.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. |
76722fa
to
f3450f1
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`
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
This is a revision of commit 659eb04 (PR python#19358), notably with following changes: - Add documentation and tests. - Raise `ValueError` for a bad mode, as in other methods. - Support multi-member removal in `_remove_members()`. - Support non-physical removal in `_remove_members()`. - Move physical file data in chunks to prevent excessive memory usage on large files. - Fix missing entry in `self.NameToInfo` when removing a duplicated archive name. - Also update `ZipInfo._end_offset` for physically moved files. Co-authored-by: Éric <merwok@netwok.org> (cherry picked from commit e6bc82a (PR python#103033))
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
This is a revision of commit 659eb04 (PR python#19358), notably with following changes: - Add documentation and tests. - Raise `ValueError` for a bad mode, as in other methods. - Support multi-member removal in `_remove_members()`. - Support non-physical removal in `_remove_members()`. - Move physical file data in chunks to prevent excessive memory usage on large files. - Fix missing entry in `self.NameToInfo` when removing a duplicated archive name. - Also update `ZipInfo._end_offset` for physically moved files. Co-authored-by: Éric <merwok@netwok.org> (cherry picked from commit e6bc82a (PR python#103033))
- File is not truncated in mode 'w'/'x', which results non-shrinked file. - This cannot be simply resolved by adding truncation for mode 'w'/'x', which may be used on an unseekable file buffer and truncation is not allowed.
- The seek will be automatically called in `ZipFile.close`.
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
ZipFile.remove()
The PR is being old and the base python executable can be hardly compiled. Rebased onto the latest Python and make sure it builds, with few trivial commits squashed together. |
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 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 objects #51067 (comment) and remove/delete method for zipfile 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.