gh-113767: Adds a zipfile.register_compressor()
API.
#113768
Draft
+668
−127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This refactors
zipfile
to add aregister_compression()
API and uses the API for all of our built-in stdlib based compressors (zlib's deflate, bz2, and lzma).This allows additional compression methods to be officially supplied by third party libraries without monkeypatching the zipfile module. It is designed to obsolete the gross hacks that things like https://pypi.org/project/zipfile-zstd/ have to do.
Motivation: zstandard support in zipfile, without adding a zstandard implementation to the standard library and without using monkeypatching. But I'm sure others will find it useful as well. Another potential use case is enabling the use of optimized compressors (think parallelized zlib's like pigz) instead of the stdlib default implementations.
TODO items:
zipfile.register_compression
docstring for now).