77using System . Collections ;
88using System . Collections . Generic ;
99using System . IO ;
10+ using System . Linq ;
1011using System . Security . Cryptography ;
1112using System . Text ;
1213
@@ -504,6 +505,7 @@ public ZipFile(Stream stream) :
504505 /// </summary>
505506 /// <param name="stream">The <see cref="Stream"/> to read archive data from.</param>
506507 /// <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>
507509 /// <exception cref="IOException">
508510 /// An i/o error occurs
509511 /// </exception>
@@ -516,7 +518,7 @@ public ZipFile(Stream stream) :
516518 /// <exception cref="ArgumentNullException">
517519 /// The <see cref="Stream">stream</see> argument is null.
518520 /// </exception>
519- public ZipFile ( Stream stream , bool leaveOpen )
521+ public ZipFile ( Stream stream , bool leaveOpen , StringCodec stringCodec = null )
520522 {
521523 if ( stream == null )
522524 {
@@ -531,6 +533,11 @@ public ZipFile(Stream stream, bool leaveOpen)
531533 baseStream_ = stream ;
532534 isStreamOwner = ! leaveOpen ;
533535
536+ if ( stringCodec != null )
537+ {
538+ _stringCodec = stringCodec ;
539+ }
540+
534541 if ( baseStream_ . Length > 0 )
535542 {
536543 try
@@ -736,14 +743,20 @@ public ZipEntry this[int index]
736743 public Encoding ZipCryptoEncoding
737744 {
738745 get => _stringCodec . ZipCryptoEncoding ;
739- set => _stringCodec . ZipCryptoEncoding = value ;
746+ set => _stringCodec = _stringCodec . WithZipCryptoEncoding ( value ) ;
740747 }
741748
742749 /// <inheritdoc cref="Zip.StringCodec"/>
743750 public StringCodec StringCodec
744751 {
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+ }
747760 }
748761
749762 #endregion Properties
@@ -1592,7 +1605,7 @@ public void CommitUpdate()
15921605 {
15931606 RunUpdates ( ) ;
15941607 }
1595- else if ( commentEdited_ )
1608+ else if ( commentEdited_ && ! isNewArchive_ )
15961609 {
15971610 UpdateCommentOnly ( ) ;
15981611 }
0 commit comments