关于 ANSI 编码 ,在中文 Windows 系统中可能是 GBK 编码,而在其他语言的 Windows 系统又可能是别的。可以想见,Mac 下打出的压缩包在不同语言的 Windows 下会乱得各具特色。
当然,并不是所有解压缩软件都会一股脑地用 ANSI 编码进行解压。有的解压软件能够自动识别(文件名)编码并不确定的时候请使用者选择,比如 Mac 下的 The Unarchiver。根据我在中文 Win7 下的测试,不同的解压缩软件对压缩文件的默认“理解”也是不同的,快压会解出乱码,而 7zip、Winrar 则可以正确解码。
一种直观的想法是,可以对文件名给出统一编码格式或者将编码写进压缩文件供解压缩程序读取。然而,Zip files and Encoding – I hate you. 中提到
The Zip spec does not seem to know that there are normalization models for UTF-8, when there are actually 4 (or more, because there is some non-standard ones too!). The Zip file gives no guidance as to how file names inside zip files are to be normalized.
…
The Zip spec says that the only supported encodings are CP437 and UTF-8, but everyone has ignored that. Implementers just encode file names however they want (usually byte for byte as they are in the OS…
很遗憾,Mac 自带的 zip 命令就属于最后一句中 Implementers。虽然我不是很清楚“文件头中没有声明 PKZIP 高版本增加的 Unicode 位”中的细节,不过后来通过比较发现,无乱码和有乱码的 zip 文件,以 16进制方式查看时,文件名中中文字符的编码是一样的,不同之处确实在 zip 文件头。