38
38
39
39
__all__ = ["BadZipFile" , "BadZipfile" , "error" ,
40
40
"ZIP_STORED" , "ZIP_DEFLATED" , "ZIP_BZIP2" , "ZIP_LZMA" ,
41
- "is_zipfile " , "ZipInfo " , "ZipFile " , "PyZipFile " , "LargeZipFile " ,
42
- "Path" ]
41
+ "ZIP_ZSTANDARD " , "is_zipfile " , "ZipInfo " , "ZipFile " , "PyZipFile " ,
42
+ "LargeZipFile" , " Path" ]
43
43
44
44
class BadZipFile (Exception ):
45
45
pass
@@ -812,11 +812,11 @@ def _get_compressor(compress_type, compresslevel=None):
812
812
if compresslevel is not None :
813
813
return bz2 .BZ2Compressor (compresslevel )
814
814
return bz2 .BZ2Compressor ()
815
- # compresslevel is ignored for ZIP_LZMA and ZIP_ZSTANDARD
815
+ # compresslevel is ignored for ZIP_LZMA
816
816
elif compress_type == ZIP_LZMA :
817
817
return LZMACompressor ()
818
818
elif compress_type == ZIP_ZSTANDARD :
819
- return zstd .ZstdCompressor ()
819
+ return zstd .ZstdCompressor (level = compresslevel )
820
820
else :
821
821
return None
822
822
@@ -1352,7 +1352,8 @@ class ZipFile:
1352
1352
mode: The mode can be either read 'r', write 'w', exclusive create 'x',
1353
1353
or append 'a'.
1354
1354
compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib),
1355
- ZIP_BZIP2 (requires bz2) or ZIP_LZMA (requires lzma).
1355
+ ZIP_BZIP2 (requires bz2), ZIP_LZMA (requires lzma), or
1356
+ ZIP_ZSTANDARD (requires compression.zstd).
1356
1357
allowZip64: if True ZipFile will create files with ZIP64 extensions when
1357
1358
needed, otherwise it will raise an exception when this would
1358
1359
be necessary.
@@ -1361,6 +1362,9 @@ class ZipFile:
1361
1362
When using ZIP_STORED or ZIP_LZMA this keyword has no effect.
1362
1363
When using ZIP_DEFLATED integers 0 through 9 are accepted.
1363
1364
When using ZIP_BZIP2 integers 1 through 9 are accepted.
1365
+ When using ZIP_ZSTANDARD integers -7 though 22 are common,
1366
+ see the CompressionParameter enum in compression.zstd for
1367
+ details.
1364
1368
1365
1369
"""
1366
1370
@@ -2093,6 +2097,8 @@ def _write_end_record(self):
2093
2097
min_version = max (BZIP2_VERSION , min_version )
2094
2098
elif zinfo .compress_type == ZIP_LZMA :
2095
2099
min_version = max (LZMA_VERSION , min_version )
2100
+ elif zinfo .compress_type == ZIP_ZSTANDARD :
2101
+ min_version = max (ZSTANDARD_VERSION , min_version )
2096
2102
2097
2103
extract_version = max (min_version , zinfo .extract_version )
2098
2104
create_version = max (min_version , zinfo .create_version )
0 commit comments