Skip to content

Commit 9e94209

Browse files
committed
Revise docstring
1 parent 93f4c25 commit 9e94209

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

Lib/zipfile/__init__.py

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,67 +1380,71 @@ def _debug(self, level, *msg):
13801380

13811381
def repack(self, zfile, removed=None):
13821382
"""
1383-
Repack the ZIP file, removing unrecorded local file entries and random
1384-
bytes not listed in the central directory.
1383+
Repack the ZIP file, stripping unreferenced local file entries.
13851384
1386-
Assumes that local file entries are written consecutively without gaps.
1385+
Assumes that local file entries are stored consecutively, with no gaps
1386+
or overlaps.
13871387
1388-
Truncation is applied in two phases:
1388+
Stripping occurs in two phases:
13891389
13901390
1. Before the first recorded file entry:
13911391
- If a sequence of valid local file entries (starting with
1392-
`PK\x03\x04`) is found leading up to the first recorded entry,
1393-
it is truncated.
1392+
`PK\x03\x04`) is found immediately before the first recorded
1393+
entry, it is stripped.
13941394
- Otherwise, all leading bytes are preserved (e.g., in cases such
1395-
as self-extracting code or embedded ZIP libraries).
1395+
as self-extracting archives or embedded ZIP payloads).
13961396
13971397
2. Between or after the recorded entries:
1398-
- Any data between two recorded entries, or after the last recorded
1399-
entry but before the central directory, is removed—regardless of
1400-
whether it resembles a valid entry.
1398+
- Any bytes between two recorded entries, or between the last
1399+
recorded and the central directory, are removed—regardless of
1400+
whether they resemble valid entries.
14011401
1402-
### Examples
1402+
Examples:
14031403
1404-
Truncation before first recorded entry:
1404+
Stripping before first recorded entry:
14051405
14061406
[random bytes]
1407-
[unrecorded local file entry 1]
1408-
[unrecorded local file entry 2]
1407+
[unreferenced local file entry 1]
1408+
[unreferenced local file entry 2]
14091409
[random bytes]
1410-
<- truncation start
1411-
[unrecorded local file entry 3]
1412-
[unrecorded local file entry 4]
1413-
<- truncation end
1410+
<-- stripping start
1411+
[unreferenced local file entry 3]
1412+
[unreferenced local file entry 4]
1413+
<-- stripping end
14141414
[recorded local file entry 1]
14151415
...
14161416
[central directory]
14171417
1418-
Truncation between recorded entries:
1418+
Stripping between recorded entries:
14191419
14201420
...
14211421
[recorded local file entry 5]
1422-
<- truncation start
1422+
<-- stripping start
14231423
[random bytes]
1424-
[unrecorded local file entry]
1424+
[unreferenced local file entry]
14251425
[random bytes]
1426-
<- truncation end
1426+
<-- stripping end
14271427
[recorded local file entry 6]
14281428
...
14291429
[recorded local file entry n]
1430-
<- truncation start
1431-
[unrecorded local file entry]
1432-
<- truncation end
1430+
<-- stripping start
1431+
[unreferenced local file entry]
1432+
<-- stripping end
14331433
[central directory]
14341434
1435-
No truncation case:
1435+
No stripping:
14361436
1437-
[unrecorded local file entry 1]
1438-
[unrecorded local file entry 2]
1437+
[unreferenced local file entry 1]
1438+
[unreferenced local file entry 2]
14391439
...
1440-
[unrecorded local file entry n]
1440+
[unreferenced local file entry n]
14411441
[random bytes]
14421442
[recorded local file entry 1]
14431443
...
1444+
1445+
removed: None or a sequence of ZipInfo instances representing removed
1446+
entries. When provided, only their corresponding local file
1447+
entries are stripped.
14441448
"""
14451449
removed_zinfos = set(removed or ())
14461450

0 commit comments

Comments
 (0)