-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Compression level for zipfile #65616
Comments
This is a fork from this ticket: http://bugs.python.org/issue21404 tarfile has a compression level and seems to get now the missing documentation for it. But there is still a compression level missing for zipfile. |
btw. hacked work-a-round is: zlib.Z_DEFAULT_COMPRESSION = 9 |
Would compresslevel be a suitable argument? All the backend compressors accept values from 1 to 9 if I'm not mistaken. |
Yes, it would make sence or better yet have a arg that is optional that if not set make it = |
I thought about that, but:
|
I have a concern about the _compresslevel attribute of ZipInfo. Why is it underscored and not documented? |
I made a comment about that in the pull request that went unchallenged ([1]), but I'm happy to change it. [1] #5385 (review) |
keeping the conversation in one place, the code review comment was: "I've prefixed this with an underscore because it's not exposed when reading back. ZipInfo has another "private" attribute, _raw_time" compresslevel is documented on the public APIs where it appears, I do not believe it needs to be a public attribute within ZipInfo given the above as that is an implementation detail. If we ever find a good reason to make it public in the future we can add a property. |
This makes sense to me. Thank you for explanation. |
@gpshead so is it a bug or a feature that adding files to archive using In the library code there is: # Make sure we have an info object
if isinstance(name, ZipInfo):
# 'name' is already an info object
zinfo = name So it takes zipinfo._compresslevel = 9 Or am I missing something here? |
As pointed out in https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.writestr when creating a ZipInfo it defaults to ZIP_STORED, which means the compression passed to zipfile.ZipFile() is ignored. This leads to the wheels files being uncompressed. To fix this copy over the compression type from the ZipFile instance. Note that the same is true for the compression level, but it's not used anyway, and there is currently no public API to set it, see python/cpython#65616 (comment) Fixes mesonbuild#519
As pointed out in https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.writestr when creating a ZipInfo it defaults to ZIP_STORED, which means the compression passed to zipfile.ZipFile() is ignored. This leads to the wheels files being uncompressed. To fix this copy over the compression type from the ZipFile instance. Note that the same is true for the compression level, but it's not used, and there is currently no public API to set it, see python/cpython#65616 (comment) Fixes mesonbuild#519
As pointed out in https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.writestr when creating a ZipInfo it defaults to ZIP_STORED, which means the compression passed to zipfile.ZipFile() is ignored. This leads to the wheel file being uncompressed. To fix this copy over the compression type from the ZipFile instance. Note that the same is true for the compression level, but it's not used, and there is currently no public API to set it, see python/cpython#65616 (comment) Fixes mesonbuild#519
As pointed out in https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.writestr when creating a ZipInfo it defaults to ZIP_STORED, which means the compression passed to zipfile.ZipFile() is ignored. This leads to the wheel file being uncompressed. To fix this copy over the compression type from the ZipFile instance. Note that the same is true for the compression level, but it's not used, and there is currently no public API to set it, see python/cpython#65616 (comment) Fixes mesonbuild#519
@zborro Because I just had a similar issue. You don't need to set the private field, you can pass compresslevel to writestr() instead: |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: