8000 gh-132983: Fix small issues with zstd support in zipfile (#133723) · python/cpython@35f47d0 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 header class="HeaderMktg header-logged-out js-details-container js-header Details f4 py-3" role="banner" data-is-top="true" data-color-mode=light data-light-theme=light data-dark-theme=dark>

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 35f47d0

Browse files
pR0PsAA-Turneremmatyping
authored
gh-132983: Fix small issues with zstd support in zipfile (#133723)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Emma Smith <emma@emmatyping.dev>
1 parent 18bf8f8 commit 35f47d0

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Lib/zipfile/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838

3939
__all__ = ["BadZipFile", "BadZipfile", "error",
4040
"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"]
4343

4444
class BadZipFile(Exception):
4545
pass
@@ -812,11 +812,11 @@ def _get_compressor(compress_type, compresslevel=None):
812812
if compresslevel is not None:
813813
return bz2.BZ2Compressor(compresslevel)
814814
return bz2.BZ2Compressor()
815-
# compresslevel is ignored for ZIP_LZMA and ZIP_ZSTANDARD
815+
# compresslevel is ignored for ZIP_LZMA
816816
elif compress_type == ZIP_LZMA:
817817
return LZMACompressor()
818818
elif compress_type == ZIP_ZSTANDARD:
819-
return zstd.ZstdCompressor()
819+
return zstd.ZstdCompressor(level=compresslevel)
820820
else:
821821
return None
822822

@@ -1352,7 +1352,8 @@ class ZipFile:
13521352
mode: The mode can be either read 'r', write 'w', exclusive create 'x',
13531353
or append 'a'.
13541354
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).
13561357
allowZip64: if True ZipFile will create files with ZIP64 extensions when
13571358
needed, otherwise it will raise an exception when this would
13581359
be necessary.
@@ -1361,6 +1362,9 @@ class ZipFile:
13611362
When using ZIP_STORED or ZIP_LZMA this keyword has no effect.
13621363
When using ZIP_DEFLATED integers 0 through 9 are accepted.
13631364
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.
13641368
13651369
"""
13661370

@@ -2093,6 +2097,8 @@ def _write_end_record(self):
20932097
min_version = max(BZIP2_VERSION, min_version)
20942098
elif zinfo.compress_type == ZIP_LZMA:
20952099
min_version = max(LZMA_VERSION, min_version)
2100+
elif zinfo.compress_type == ZIP_ZSTANDARD:
2101+
min_version = max(ZSTANDARD_VERSION, min_version)
20962102

20972103
extract_version = max(min_version, zinfo.extract_version)
20982104
create_version = max(min_version, zinfo.create_version)

0 commit comments

Comments
 (0)
0