Skip to content

Commit eb29a30

Browse files
committed
gh-51067: Add _REPACK_CHUNK_SIZE constant
Single source of truth for the 1 MiB default used by both ZipFile.repack() and _ZipRepacker.
1 parent e7125e7 commit eb29a30

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

Lib/test/test_zipfile/test_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,8 @@ def test_repack_propagation(self):
18281828
with mock.patch.object(zipfile._ZipRepacker, 'repack') as m_rp, \
18291829
mock.patch.object(zipfile, '_ZipRepacker', wraps=zipfile._ZipRepacker) as m_zr:
18301830
zh.repack()
1831-
m_zr.assert_called_once_with(strict_descriptor=True, chunk_size=2**20)
1831+
m_zr.assert_called_once_with(strict_descriptor=True,
1832+
chunk_size=zipfile._REPACK_CHUNK_SIZE)
18321833
m_rp.assert_called_once_with(zh, None)
18331834

18341835
with zipfile.ZipFile(TESTFN, 'a', self.compression) as zh:

Lib/zipfile/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,9 +1394,13 @@ def close(self):
13941394
self._zipfile._writing = False
13951395

13961396

1397+
_REPACK_CHUNK_SIZE = 2**20
1398+
1399+
13971400
class _ZipRepacker:
13981401
"""Class for ZipFile repacking."""
1399-
def __init__(self, *, strict_descriptor=True, chunk_size=2**20, debug=0):
1402+
def __init__(self, *, strict_descriptor=True,
1403+
chunk_size=_REPACK_CHUNK_SIZE, debug=0):
14001404
self.debug = debug # Level of printing: 0 through 3
14011405
self.chunk_size = chunk_size
14021406
self.strict_descriptor = strict_descriptor
@@ -2388,7 +2392,8 @@ def remove(self, zinfo_or_arcname):
23882392

23892393
return zinfo
23902394

2391-
def repack(self, removed=None, *, strict_descriptor=True, chunk_size=2**20):
2395+
def repack(self, removed=None, *, strict_descriptor=True,
2396+
chunk_size=_REPACK_CHUNK_SIZE):
23922397
"""Repack a zip file, removing non-referenced file entries.
23932398
23942399
The archive must be opened with mode 'a', as mode 'w'/'x' do not

0 commit comments

Comments
 (0)