20
20
_HASH_ALG = "sha256"
21
21
_HASH_BUF_SIZE = 65536
22
22
_MINIMUM_TIMESTAMP = 315532800 # 1980-01-01 00:00:00 UTC
23
- _COMPRESSION = ZIP_DEFLATED
23
+ _DEFAULT_COMPRESSION = ZIP_DEFLATED
24
24
_WHEEL_VERSION = "1.0"
25
25
_META_TEMPLATE = f"""\
26
26
Wheel-Version: { _WHEEL_VERSION }
@@ -43,13 +43,15 @@ def __init__(
43
43
self ,
44
44
path : _Path ,
45
45
root_is_purelib : bool = True ,
46
+ compression : int = _DEFAULT_COMPRESSION ,
46
47
generator : Optional [str ] = None ,
47
48
timestamp : Optional [int ] = None ,
48
49
):
49
50
self ._path = Path (path )
50
51
self ._root_is_purelib = root_is_purelib
51
52
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 )
53
55
self ._records : Dict [str , Tuple [str , int ]] = {}
54
56
55
57
basename = str (self ._path .with_suffix ("" ).name )
@@ -83,7 +85,7 @@ def add_existing_file(self, arcname: str, file: _Path):
83
85
zipinfo = ZipInfo (arcname , self ._timestamp )
84
86
attr = stat .S_IMODE (file_stat .st_mode ) | stat .S_IFMT (file_stat .st_mode )
85
87
zipinfo .external_attr = attr << 16
86
- zipinfo .compress_type = _COMPRESSION
88
+ zipinfo .compress_type = self . _compression
87
89
88
90
with open (file , "rb" ) as src , self ._zip .open (zipinfo , "w" ) as dst :
89
91
while True :
@@ -126,7 +128,7 @@ def new_file(self, arcname: str, contents: _StrOrIter, permissions: int = 0o664)
126
128
"""
127
129
zipinfo = ZipInfo (arcname , self ._timestamp )
128
130
zipinfo .external_attr = (permissions | stat .S_IFREG ) << 16
129
- zipinfo .compress_type = _COMPRESSION
131
+ zipinfo .compress_type = self . _compression
130
132
hashsum = hashlib .new (_HASH_ALG )
131
133
file_size = 0
132
134
iter_contents = [contents ] if isinstance (contents , str ) else contents
@@ -142,7 +144,7 @@ def _save_record(self):
142
144
arcname = f"{ self ._dist_info } /RECORD"
143
145
zipinfo = ZipInfo (arcname , self ._timestamp )
144
146
zipinfo .external_attr = (0o664 | stat .S_IFREG ) << 16
145
- zipinfo .compress_type = _COMPRESSION
147
+ zipinfo .compress_type = self . _compression
146
148
out = self ._zip .open (zipinfo , "w" )
147
149
buf = io .TextIOWrapper (out , encoding = "utf-8" )
148
150
with out , buf :
0 commit comments