@@ -1667,11 +1667,7 @@ public void Add(string fileName, CompressionMethod compressionMethod, bool useUn
1667
1667
throw new ObjectDisposedException ( "ZipFile" ) ;
1668
1668
}
1669
1669
1670
- if ( ! ZipEntry . IsCompressionMethodSupported ( compressionMethod ) )
1671
- {
1672
- throw new ArgumentOutOfRangeException ( nameof ( compressionMethod ) ) ;
1673
- }
1674
-
1670
+ CheckSupportedCompressionMethod ( compressionMethod ) ;
1675
1671
CheckUpdating ( ) ;
1676
1672
contentsEdited_ = true ;
1677
1673
@@ -1696,11 +1692,7 @@ public void Add(string fileName, CompressionMethod compressionMethod)
1696
1692
throw new ArgumentNullException ( nameof ( fileName ) ) ;
1697
1693
}
1698
1694
1699
- if ( ! ZipEntry . IsCompressionMethodSupported ( compressionMethod ) )
1700
- {
1701
- throw new ArgumentOutOfRangeException ( nameof ( compressionMethod ) ) ;
1702
- }
1703
-
1695
+ CheckSupportedCompressionMethod ( compressionMethod ) ;
1704
1696
CheckUpdating ( ) ;
1705
1697
contentsEdited_ = true ;
1706
1698
@@ -1774,6 +1766,7 @@ public void Add(IStaticDataSource dataSource, string entryName)
1774
1766
/// <param name="dataSource">The source of the data for this entry.</param>
1775
1767
/// <param name="entryName">The name to give to the entry.</param>
1776
1768
/// <param name="compressionMethod">The compression method to use.</param>
1769
+ /// <exception cref="ArgumentOutOfRangeException">The compression method is not supported.</exception>
1777
1770
public void Add ( IStaticDataSource dataSource , string entryName , CompressionMethod compressionMethod )
1778
1771
{
1779
1772
if ( dataSource == null )
@@ -1786,6 +1779,7 @@ public void Add(IStaticDataSource dataSource, string entryName, CompressionMetho
1786
1779
throw new ArgumentNullException ( nameof ( entryName ) ) ;
1787
1780
}
1788
1781
1782
+ CheckSupportedCompressionMethod ( compressionMethod ) ;
1789
1783
CheckUpdating ( ) ;
1790
1784
1791
1785
ZipEntry entry = EntryFactory . MakeFileEntry ( entryName , false ) ;
@@ -1801,6 +1795,7 @@ public void Add(IStaticDataSource dataSource, string entryName, CompressionMetho
1801
1795
/// <param name="entryName">The name to give to the entry.</param>
1802
1796
/// <param name="compressionMethod">The compression method to use.</param>
1803
1797
/// <param name="useUnicodeText">Ensure Unicode text is used for name and comments for this entry.</param>
1798
+ /// <exception cref="ArgumentOutOfRangeException">The compression method is not supported.</exception>
1804
1799
public void Add ( IStaticDataSource dataSource , string entryName , CompressionMethod compressionMethod , bool useUnicodeText )
1805
1800
{
1806
1801
if ( dataSource == null )
@@ -1813,6 +1808,7 @@ public void Add(IStaticDataSource dataSource, string entryName, CompressionMetho
1813
1808
throw new ArgumentNullException ( nameof ( entryName ) ) ;
1814
1809
}
1815
1810
1811
+ CheckSupportedCompressionMethod ( compressionMethod ) ;
1816
1812
CheckUpdating ( ) ;
1817
1813
1818
1814
ZipEntry entry = EntryFactory . MakeFileEntry ( entryName , false ) ;
@@ -1850,6 +1846,7 @@ public void Add(ZipEntry entry)
1850
1846
/// <param name="dataSource">The source of the data for this entry.</param>
1851
1847
/// <param name="entry">The entry to add.</param>
1852
1848
/// <remarks>This can be used to add file entries with a custom data source.</remarks>
1849
+ /// <exception cref="ArgumentOutOfRangeException">The compression method is not supported.</exception>
1853
1850
public void Add ( IStaticDataSource dataSource , ZipEntry entry )
1854
1851
{
1855
1852
if ( entry == null )
@@ -1862,6 +1859,7 @@ public void Add(IStaticDataSource dataSource, ZipEntry entry)
1862
1859
throw new ArgumentNullException ( nameof ( dataSource ) ) ;
1863
1860
}
1864
1861
1862
+ CheckSupportedCompressionMethod ( entry . CompressionMethod ) ;
1865
1863
CheckUpdating ( ) ;
1866
1864
1867
1865
AddUpdate ( new ZipUpdate ( dataSource , entry ) ) ;
@@ -1884,6 +1882,18 @@ public void AddDirectory(string directoryName)
1884
1882
AddUpdate ( new ZipUpdate ( UpdateCommand . Add , dirEntry ) ) ;
1885
1883
}
1886
1884
1885
+ /// <summary>
1886
+ /// Check if the specified compression method is supported for adding a new entry.
1887
+ /// </summary>
1888
+ /// <param name="compressionMethod">The compression method for the new entry.</param>
1889
+ private void CheckSupportedCompressionMethod ( CompressionMethod compressionMethod )
1890
+ {
1891
+ if ( compressionMethod != CompressionMethod . Deflated && compressionMethod != CompressionMethod . Stored )
1892
+ {
1893
+ throw new ArgumentOutOfRangeException ( nameof ( compressionMethod ) , "Compression method not supported" ) ;
1894
+ }
1895
+ }
1896
+
1887
1897
#endregion Adding Entries
1888
1898
1889
1899
#region Modifying Entries
0 commit comments