2020_HASH_ALG = "sha256"
2121_HASH_BUF_SIZE = 65536
2222_MINIMUM_TIMESTAMP = 315532800 # 1980-01-01 00:00:00 UTC
23- _COMPRESSION = ZIP_DEFLATED
23+ _DEFAULT_COMPRESSION = ZIP_DEFLATED
2424_WHEEL_VERSION = "1.0"
2525_META_TEMPLATE = f"""\
2626 Wheel-Version: { _WHEEL_VERSION }
@@ -43,13 +43,15 @@ def __init__(
4343 self ,
4444 path : _Path ,
4545 root_is_purelib : bool = True ,
46+ compression : int = _DEFAULT_COMPRESSION ,
4647 generator : Optional [str ] = None ,
4748 timestamp : Optional [int ] = None ,
4849 ):
4950 self ._path = Path (path )
5051 self ._root_is_purelib = root_is_purelib
5152 self ._generator = generator
52- self ._zip = ZipFile (self ._path , "w" , compression = _COMPRESSION )
53+ self ._compression = compression
54+ self ._zip = ZipFile (self ._path , "w" , compression = compression )
5355 self ._records : Dict [str , Tuple [str , int ]] = {}
5456
5557 basename = str (self ._path .with_suffix ("" ).name )
@@ -83,7 +85,7 @@ def add_existing_file(self, arcname: str, file: _Path):
8385 zipinfo = ZipInfo (arcname , self ._timestamp )
8486 attr = stat .S_IMODE (file_stat .st_mode ) | stat .S_IFMT (file_stat .st_mode )
8587 zipinfo .external_attr = attr << 16
86- zipinfo .compress_type = _COMPRESSION
88+ zipinfo .compress_type = self . _compression
8789
8890 with open (file , "rb" ) as src , self ._zip .open (zipinfo , "w" ) as dst :
8991 while True :
@@ -126,7 +128,7 @@ def new_file(self, arcname: str, contents: _StrOrIter, permissions: int = 0o664)
126128 """
127129 zipinfo = ZipInfo (arcname , self ._timestamp )
128130 zipinfo .external_attr = (permissions | stat .S_IFREG ) << 16
129- zipinfo .compress_type = _COMPRESSION
131+ zipinfo .compress_type = self . _compression
130132 hashsum = hashlib .new (_HASH_ALG )
131133 file_size = 0
132134 iter_contents = [contents ] if isinstance (contents , str ) else contents
@@ -142,7 +144,7 @@ def _save_record(self):
142144 arcname = f"{ self ._dist_info } /RECORD"
143145 zipinfo = ZipInfo (arcname , self ._timestamp )
144146 zipinfo .external_attr = (0o664 | stat .S_IFREG ) << 16
145- zipinfo .compress_type = _COMPRESSION
147+ zipinfo .compress_type = self . _compression
146148 out = self ._zip .open (zipinfo , "w" )
147149 buf = io .TextIOWrapper (out , encoding = "utf-8" )
148150 with out , buf :
0 commit comments