Movatterモバイル変換


[0]ホーム

URL:


Skip to content

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

Sign up
Appearance settings

Commit35f47d0

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 parent18bf8f8 commit35f47d0

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
classBadZipFile(Exception):
4545
pass
@@ -812,11 +812,11 @@ def _get_compressor(compress_type, compresslevel=None):
812812
ifcompresslevelisnotNone:
813813
returnbz2.BZ2Compressor(compresslevel)
814814
returnbz2.BZ2Compressor()
815-
# compresslevel is ignored for ZIP_LZMA and ZIP_ZSTANDARD
815+
# compresslevel is ignored for ZIP_LZMA
816816
elifcompress_type==ZIP_LZMA:
817817
returnLZMACompressor()
818818
elifcompress_type==ZIP_ZSTANDARD:
819-
returnzstd.ZstdCompressor()
819+
returnzstd.ZstdCompressor(level=compresslevel)
820820
else:
821821
returnNone
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
elifzinfo.compress_type==ZIP_LZMA:
20952099
min_version=max(LZMA_VERSION,min_version)
2100+
elifzinfo.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)

[8]ページ先頭

©2009-2025 Movatter.jp