Cannot set encoded comment for zip archive using sharpZipLib

36 Views Asked by At

I need the comment for the zip file to be properly encoded. In particular, I have Greek characters in comment. After creating the zip file, the characters become question marks. Here is the code I use:

using var fs = File.Create(fileName);
using var zs = new ZipOutputStream(fs);
zs.SetLevel(0);
zs.ZipCryptoEncoding = Encoding.UTF8; // I tried to set this, but it didn't work
zs.SetComment(JsonConvert.SerializeObject(data1, data2));

Is there a way to properly encode the Comment?

Update: I also tried to the constructor with StringCodec. It didn't work either.

var zs = new ZipOutputStream(fs, StringCodec.Default);
1

There are 1 best solutions below

0
L_A_Hooper On

var zs = new ZipOutputStream(fileStream, StringCodec.FromEncoding(Encoding.UTF8)); solved the issue.