@@ -1817,6 +1817,38 @@ def test_repack_file_entry_before_first_file(self):
18171817 # check file size
18181818 self .assertEqual (os .path .getsize (TESTFN ), expected_size )
18191819
1820+ def test_repack_bytes_between_files (self ):
1821+ """Should remove bytes between local file entries."""
1822+ for ii in ([1 ], [1 , 2 ], [2 ]):
1823+ with self .subTest (remove = ii ):
1824+ # calculate the expected results
1825+ test_files = [data for j , data in enumerate (self .test_files ) if j not in ii ]
1826+ expected_zinfos = self ._prepare_zip_from_test_files (TESTFN , test_files )
1827+ expected_size = os .path .getsize (TESTFN )
1828+
1829+ # do the removal and check the result
1830+ with open (TESTFN , 'wb' ) as fh :
1831+ with zipfile .ZipFile (fh , 'w' , self .compression ) as zh :
1832+ for i , (file , data ) in enumerate (self .test_files ):
1833+ zh .writestr (file , data )
1834+ fh .write (b' dummy bytes ' )
1835+ with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1836+ for i in ii :
1837+ zh .remove (self .test_files [i ][0 ])
1838+ zh .repack ()
1839+
1840+ # check infolist
1841+ self .assertEqual (
1842+ [ComparableZipInfo (zi ) for zi in zh .infolist ()],
1843+ expected_zinfos ,
1844+ )
1845+
1846+ # make sure the zip file is still valid
1847+ self .assertIsNone (zh .testzip ())
1848+
1849+ # check file size
1850+ self .assertEqual (os .path .getsize (TESTFN ), expected_size )
1851+
18201852 def test_repack_zip64 (self ):
18211853 """Should correctly handle file entries with zip64."""
18221854 for ii in ([0 ], [0 , 1 ], [1 ], [2 ]):
0 commit comments