Correctly decoding zip entry file names — CP437, UTF-8 or?

前端 未结 2 1234
無奈伤痛
無奈伤痛 2020-12-19 01:43

I recently wrote a zip file I/O library called zipzap, but I\'m struggling with correctly decoding zip entry file names from arbitrary zip files.

Now, the PKWARE spe

相关标签:
2条回答
  • 2020-12-19 02:28

    At the moment situation is as following:

    • most of Windows implementations use DOS (OEM) encoding
    • Mac OS zip utility uses utf-8, but it doesn't set utf-8 bit flags
    • *nix zip utilities silently uses system encoding

    So the only way is to check if filename contains something like utf-8 characters (check description of utf8 encoding - first byte should be 110xxxxx, second - 10xxxxxx for 2-bytes encoded chars). If it is correct utf8 string - use utf8 encoding. If not - fall back to OEM/DOS encoding.

    0 讨论(0)
  • 2020-12-19 02:29

    The only way to determine if the filename is encoded as UTF-8 without using the EFS flag is to check to see if the high order bit is set in one of the characters. That could possibly mean that the character is UTF-8 encoded. However, it could still be the other way as there are some characters in CP437 that have the high order bit set and aren't meant to be decoded as UTF-8.

    I would stick to the PKWARE app note specification and not hack in a solution that tries to conform to every known zip application in existence.

    0 讨论(0)
提交回复
热议问题