icsharpcode / SharpZipLib

#ziplib is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform.
http://icsharpcode.github.io/SharpZipLib/
MIT License
3.71k stars 979 forks source link

No way to set StringCodec on ZipInputStream & ZipOutputStream #776

Closed zhuxb711 closed 2 years ago

zhuxb711 commented 2 years ago

[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)

piksel commented 2 years ago

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.

zhuxb711 commented 2 years ago

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