@@ -1654,7 +1654,7 @@ private void AddUpdate(ZipUpdate update)
16541654 /// <param name="useUnicodeText">Ensure Unicode text is used for name and comment for this entry.</param>
16551655 /// <exception cref="ArgumentNullException">Argument supplied is null.</exception>
16561656 /// <exception cref="ObjectDisposedException">ZipFile has been closed.</exception>
1657- /// <exception cref="ArgumentOutOfRangeException ">Compression method is not supported.</exception>
1657+ /// <exception cref="NotImplementedException ">Compression method is not supported for creating entries .</exception>
16581658 public void Add ( string fileName , CompressionMethod compressionMethod , bool useUnicodeText )
16591659 {
16601660 if ( fileName == null )
@@ -1667,11 +1667,7 @@ public void Add(string fileName, CompressionMethod compressionMethod, bool useUn
16671667 throw new ObjectDisposedException ( "ZipFile" ) ;
16681668 }
16691669
1670- if ( ! ZipEntry . IsCompressionMethodSupported ( compressionMethod ) )
1671- {
1672- throw new ArgumentOutOfRangeException ( nameof ( compressionMethod ) ) ;
1673- }
1674-
1670+ CheckSupportedCompressionMethod ( compressionMethod ) ;
16751671 CheckUpdating ( ) ;
16761672 contentsEdited_ = true ;
16771673
@@ -1688,19 +1684,15 @@ public void Add(string fileName, CompressionMethod compressionMethod, bool useUn
16881684 /// <param name="fileName">The name of the file to add.</param>
16891685 /// <param name="compressionMethod">The compression method to use.</param>
16901686 /// <exception cref="ArgumentNullException">ZipFile has been closed.</exception>
1691- /// <exception cref="ArgumentOutOfRangeException">The compression method is not supported.</exception>
1687+ /// <exception cref="NotImplementedException">Compression method is not supported for creating entries .</exception>
16921688 public void Add ( string fileName , CompressionMethod compressionMethod )
16931689 {
16941690 if ( fileName == null )
16951691 {
16961692 throw new ArgumentNullException ( nameof ( fileName ) ) ;
16971693 }
16981694
1699- if ( ! ZipEntry . IsCompressionMethodSupported ( compressionMethod ) )
1700- {
1701- throw new ArgumentOutOfRangeException ( nameof ( compressionMethod ) ) ;
1702- }
1703-
1695+ CheckSupportedCompressionMethod ( compressionMethod ) ;
17041696 CheckUpdating ( ) ;
17051697 contentsEdited_ = true ;
17061698
@@ -1774,6 +1766,7 @@ public void Add(IStaticDataSource dataSource, string entryName)
17741766 /// <param name="dataSource">The source of the data for this entry.</param>
17751767 /// <param name="entryName">The name to give to the entry.</param>
17761768 /// <param name="compressionMethod">The compression method to use.</param>
1769+ /// <exception cref="NotImplementedException">Compression method is not supported for creating entries.</exception>
17771770 public void Add ( IStaticDataSource dataSource , string entryName , CompressionMethod compressionMethod )
17781771 {
17791772 if ( dataSource == null )
@@ -1786,6 +1779,7 @@ public void Add(IStaticDataSource dataSource, string entryName, CompressionMetho
17861779 throw new ArgumentNullException ( nameof ( entryName ) ) ;
17871780 }
17881781
1782+ CheckSupportedCompressionMethod ( compressionMethod ) ;
17891783 CheckUpdating ( ) ;
17901784
17911785 ZipEntry entry = EntryFactory . MakeFileEntry ( entryName , false ) ;
@@ -1801,6 +1795,7 @@ public void Add(IStaticDataSource dataSource, string entryName, CompressionMetho
18011795 /// <param name="entryName">The name to give to the entry.</param>
18021796 /// <param name="compressionMethod">The compression method to use.</param>
18031797 /// <param name="useUnicodeText">Ensure Unicode text is used for name and comments for this entry.</param>
1798+ /// <exception cref="NotImplementedException">Compression method is not supported for creating entries.</exception>
18041799 public void Add ( IStaticDataSource dataSource , string entryName , CompressionMethod compressionMethod , bool useUnicodeText )
18051800 {
18061801 if ( dataSource == null )
@@ -1813,6 +1808,7 @@ public void Add(IStaticDataSource dataSource, string entryName, CompressionMetho
18131808 throw new ArgumentNullException ( nameof ( entryName ) ) ;
18141809 }
18151810
1811+ CheckSupportedCompressionMethod ( compressionMethod ) ;
18161812 CheckUpdating ( ) ;
18171813
18181814 ZipEntry entry = EntryFactory . MakeFileEntry ( entryName , false ) ;
@@ -1850,6 +1846,7 @@ public void Add(ZipEntry entry)
18501846 /// <param name="dataSource">The source of the data for this entry.</param>
18511847 /// <param name="entry">The entry to add.</param>
18521848 /// <remarks>This can be used to add file entries with a custom data source.</remarks>
1849+ /// <exception cref="NotImplementedException">Compression method is not supported for creating entries.</exception>
18531850 public void Add ( IStaticDataSource dataSource , ZipEntry entry )
18541851 {
18551852 if ( entry == null )
@@ -1862,6 +1859,7 @@ public void Add(IStaticDataSource dataSource, ZipEntry entry)
18621859 throw new ArgumentNullException ( nameof ( dataSource ) ) ;
18631860 }
18641861
1862+ CheckSupportedCompressionMethod ( entry . CompressionMethod ) ;
18651863 CheckUpdating ( ) ;
18661864
18671865 AddUpdate ( new ZipUpdate ( dataSource , entry ) ) ;
@@ -1884,6 +1882,18 @@ public void AddDirectory(string directoryName)
18841882 AddUpdate ( new ZipUpdate ( UpdateCommand . Add , dirEntry ) ) ;
18851883 }
18861884
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 NotImplementedException ( "Compression method not supported" ) ;
1894+ }
1895+ }
1896+
18871897 #endregion Adding Entries
18881898
18891899 #region Modifying Entries
0 commit comments