@@ -1611,5 +1611,88 @@ public void AddFileWithAlternateName()
16111611 }
16121612 }
16131613 }
1614+
1615+ /// <summary>
1616+ /// Test for https://github.com/icsharpcode/SharpZipLib/issues/147, when deleting items in a zip
1617+ /// </summary>
1618+ /// <param name="useZip64">Whether Zip64 should be used in the test archive</param>
1619+ [ TestCase ( UseZip64 . On ) ]
1620+ [ TestCase ( UseZip64 . Off ) ]
1621+ [ Category ( "Zip" ) ]
1622+ public void TestDescriptorUpdateOnDelete ( UseZip64 useZip64 )
1623+ {
1624+ MemoryStream msw = new MemoryStreamWithoutSeek ( ) ;
1625+ using ( ZipOutputStream outStream = new ZipOutputStream ( msw ) )
1626+ {
1627+ outStream . UseZip64 = useZip64 ;
1628+ outStream . IsStreamOwner = false ;
1629+ outStream . PutNextEntry ( new ZipEntry ( "StripedMarlin" ) ) ;
1630+ outStream . WriteByte ( 89 ) ;
1631+
1632+ outStream . PutNextEntry ( new ZipEntry ( "StripedMarlin2" ) ) ;
1633+ outStream . WriteByte ( 91 ) ;
1634+ }
1635+
1636+ var zipData = msw . ToArray ( ) ;
1637+ Assert . IsTrue ( ZipTesting . TestArchive ( zipData ) ) ;
1638+
1639+ using ( var memoryStream = new MemoryStream ( zipData ) )
1640+ {
1641+ using ( var zipFile = new ZipFile ( memoryStream , leaveOpen : true ) )
1642+ {
1643+ zipFile . BeginUpdate ( ) ;
1644+ zipFile . Delete ( "StripedMarlin" ) ;
1645+ zipFile . CommitUpdate ( ) ;
1646+ }
1647+
1648+ memoryStream . Position = 0 ;
1649+
1650+ using ( var zipFile = new ZipFile ( memoryStream , leaveOpen : true ) )
1651+ {
1652+ Assert . That ( zipFile . TestArchive ( true ) , Is . True ) ;
1653+ }
1654+ }
1655+ }
1656+
1657+ /// <summary>
1658+ /// Test for https://github.com/icsharpcode/SharpZipLib/issues/147, when adding items to a zip
1659+ /// </summary>
1660+ /// <param name="useZip64">Whether Zip64 should be used in the test archive</param>
1661+ [ TestCase ( UseZip64 . On ) ]
1662+ [ TestCase ( UseZip64 . Off ) ]
1663+ [ Category ( "Zip" ) ]
1664+ public void TestDescriptorUpdateOnAdd ( UseZip64 useZip64 )
1665+ {
1666+ MemoryStream msw = new MemoryStreamWithoutSeek ( ) ;
1667+ using ( ZipOutputStream outStream = new ZipOutputStream ( msw ) )
1668+ {
1669+ outStream . UseZip64 = useZip64 ;
1670+ outStream . IsStreamOwner = false ;
1671+ outStream . PutNextEntry ( new ZipEntry ( "StripedMarlin" ) ) ;
1672+ outStream . WriteByte ( 89 ) ;
1673+ }
1674+
1675+ var zipData = msw . ToArray ( ) ;
1676+ Assert . IsTrue ( ZipTesting . TestArchive ( zipData ) ) ;
1677+
1678+ using ( var memoryStream = new MemoryStream ( ) )
1679+ {
1680+ memoryStream . Write ( zipData , 0 , zipData . Length ) ;
1681+
1682+ using ( var zipFile = new ZipFile ( memoryStream , leaveOpen : true ) )
1683+ {
1684+ zipFile . BeginUpdate ( ) ;
1685+ zipFile . Add ( new StringMemoryDataSource ( "stripey" ) , "Zebra" ) ;
1686+ zipFile . CommitUpdate ( ) ;
1687+ }
1688+
1689+ memoryStream . Position = 0 ;
1690+
1691+ using ( var zipFile = new ZipFile ( memoryStream , leaveOpen : true ) )
1692+ {
1693+ Assert . That ( zipFile . TestArchive ( true ) , Is . True ) ;
1694+ }
1695+ }
1696+ }
16141697 }
16151698}
0 commit comments