icsharpcode/SharpZipLib

No way to set StringCodec on ZipInputStream & ZipOutputStream

zhuxb711 opened this issue · 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

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.

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) });