You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
@gpshead so is it a bug or a feature that adding files to archive using ZipInfo completely ignores what compression type and compression level is set in the ZipFile instance?
In the library code there is:
# Make sure we have an info objectifisinstance(name, ZipInfo):
# 'name' is already an info objectzinfo=name
So it takes ZipInfo as is. If one wants to set compression level, that private field needs to be set:
So it takes ZipInfo as is. If one wants to set compression level, that private field needs to be set:
zipinfo._compresslevel=9
Or am I missing something here?
@zborro Because I just had a similar issue. You don't need to set the private field, you can pass compresslevel to writestr() instead: zip_file.writestr(zip_info, compress_type=ZIP_DEFLATED, compresslevel=9)
Activity
Sworddragon commentedon May 2, 2014
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.
jens commentedon Jun 24, 2015
btw. hacked work-a-round is:
jfoo commentedon Aug 13, 2016
Would compresslevel be a suitable argument? All the backend compressors accept values from 1 to 9 if I'm not mistaken.
AraHaan commentedon Aug 13, 2016
Yes, it would make sence or better yet have a arg that is optional that if not set make it =
9.jfoo commentedon Aug 14, 2016
I thought about that, but:
gpshead commentedon Jan 30, 2018
New changeset ce237c7 by Gregory P. Smith (Bo Bayles) in branch 'master':
bpo-21417: Add compresslevel= to the zipfile module (GH-5385)
ce237c7
serhiy-storchaka commentedon Feb 26, 2018
I have a concern about the _compresslevel attribute of ZipInfo. Why is it underscored and not documented?
bbayles commentedon Feb 26, 2018
I made a comment about that in the pull request that went unchallenged ([1]), but I'm happy to change it.
[1] #5385 (review)
gpshead commentedon Feb 26, 2018
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.
serhiy-storchaka commentedon Feb 26, 2018
This makes sense to me. Thank you for explanation.
zborro commentedon Nov 4, 2022
@gpshead so is it a bug or a feature that adding files to archive using
ZipInfocompletely ignores what compression type and compression level is set in theZipFileinstance?In the library code there is:
So it takes
ZipInfoas is. If one wants to set compression level, that private field needs to be set:Or am I missing something here?
Fix missing compression of wheels
Fix wheels not being compressed
Fix wheels not being compressed
BUG: Fix wheels not being compressed
lazka commentedon Oct 21, 2023
@zborro Because I just had a similar issue. You don't need to set the private field, you can pass compresslevel to writestr() instead:
zip_file.writestr(zip_info, compress_type=ZIP_DEFLATED, compresslevel=9)