7
7
using System . Collections ;
8
8
using System . Collections . Generic ;
9
9
using System . IO ;
10
+ using System . Linq ;
10
11
using System . Security . Cryptography ;
11
12
using System . Text ;
12
13
@@ -504,6 +505,7 @@ public ZipFile(Stream stream) :
504
505
/// </summary>
505
506
/// <param name="stream">The <see cref="Stream"/> to read archive data from.</param>
506
507
/// <param name="leaveOpen">true to leave the <see cref="Stream">stream</see> open when the ZipFile is disposed, false to dispose of it</param>
508
+ /// <param name="stringCodec"></param>
507
509
/// <exception cref="IOException">
508
510
/// An i/o error occurs
509
511
/// </exception>
@@ -516,7 +518,7 @@ public ZipFile(Stream stream) :
516
518
/// <exception cref="ArgumentNullException">
517
519
/// The <see cref="Stream">stream</see> argument is null.
518
520
/// </exception>
519
- public ZipFile ( Stream stream , bool leaveOpen )
521
+ public ZipFile ( Stream stream , bool leaveOpen , StringCodec stringCodec = null )
520
522
{
521
523
if ( stream == null )
522
524
{
@@ -531,6 +533,11 @@ public ZipFile(Stream stream, bool leaveOpen)
531
533
baseStream_ = stream ;
532
534
isStreamOwner = ! leaveOpen ;
533
535
536
+ if ( stringCodec != null )
537
+ {
538
+ _stringCodec = stringCodec ;
539
+ }
540
+
534
541
if ( baseStream_ . Length > 0 )
535
542
{
536
543
try
@@ -736,14 +743,20 @@ public ZipEntry this[int index]
736
743
public Encoding ZipCryptoEncoding
737
744
{
738
745
get => _stringCodec . ZipCryptoEncoding ;
739
- set => _stringCodec . ZipCryptoEncoding = value ;
746
+ set => _stringCodec = _stringCodec . WithZipCryptoEncoding ( value ) ;
740
747
}
741
748
742
749
/// <inheritdoc cref="Zip.StringCodec"/>
743
750
public StringCodec StringCodec
744
751
{
745
- get => _stringCodec ;
746
- set => _stringCodec = value ;
752
+ set {
753
+ _stringCodec = value ;
754
+ if ( ! isNewArchive_ )
755
+ {
756
+ // Since the string codec was changed
757
+ ReadEntries ( ) ;
758
+ }
759
+ }
747
760
}
748
761
749
762
#endregion Properties
@@ -1592,7 +1605,7 @@ public void CommitUpdate()
1592
1605
{
1593
1606
RunUpdates ( ) ;
1594
1607
}
1595
- else if ( commentEdited_ )
1608
+ else if ( commentEdited_ && ! isNewArchive_ )
1596
1609
{
1597
1610
UpdateCommentOnly ( ) ;
1598
1611
}
0 commit comments