SharpZipLib icon indicating copy to clipboard operation
SharpZipLib copied to clipboard

No way to set StringCodec on ZipInputStream & ZipOutputStream

Open zhuxb711 opened this issue 1 year ago • 2 comments

[Obsolete("Use ZipFile/Zip*Stream StringCodec instead")] I got this from the latest version. But ZipInputStream & ZipOutputStream do not provide any StingCodec property and the only one which might be useful constructor is internal image

Expected behavior

Should allow us to set the StringCodec if ZipStrings.CodePage is obsolete

Actual behavior

No way except the obsolete way to set the StringCodec

Version of SharpZipLib

1.4.0

Obtained from (only keep the relevant lines)

  • Package installed using NuGet

zhuxb711 avatar Sep 20 '22 09:09 zhuxb711

Yes, you are right, not sure how that happened. There should be getters and setters to access the internal _stringCodec, and perhaps the constructor should be public as well.

piksel avatar Sep 20 '22 13:09 piksel

Use reflection to work around this issue in case someone needs it.

StringCodec Codec = new StringCodec
{
        ForceZipLegacyEncoding = true,
        CodePage = EncodingSetting.CodePage
};

using ZipOutputStream OutputStream = (ZipOutputStream)typeof(ZipOutputStream).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder, new Type[] { typeof(Stream), typeof(StringCodec) });

zhuxb711 avatar Sep 20 '22 15:09 zhuxb711