TheBlainer
TheBlainer

Reputation: 103

Wrong encoding in ZipFile comment

I'm reading the comment of a ZIP file using the Ionic.Zip.ZipFile class and there seem to be a problem with accented characters (like éêè). In my case, instead of receiving "Éric", I get "╔ric".

My code is :

using (ZipFile zipFile = new ZipFile(path))
{
  comment = zipFile.Comment;
}

Path is the path of the ZIP File. I also tried to put the encoding directly, but same result (like this) :

using (ZipFile zipFile = new ZipFile(path, Encoding.UTF8))
{
  comment = zipFile.Comment;
}

Is there a specific encoding for the comment?

Upvotes: 2

Views: 1368

Answers (1)

TheBlainer
TheBlainer

Reputation: 103

Thanks to Moby Disk, I found the solution. You need to get the right encoding of the comment before encoding it to the one you use (in my case the default one).

The code is as follow :

using (ZipFile zipFile = new ZipFile(path))
{
  byte[] bytes = Encoding.GetEncoding(437).GetBytes(zipFile.Comment);
  comment = Encoding.Default.GetString(bytes);
}

Upvotes: 1

Related Questions