Mac的文件名
mac机的文件名真的很特殊. 因为他进行了unicode编码. 准确的说是nfd编码
参考:
- https://zh.wikipedia.org/wiki/Unicode等價性
- https://cloud.google.com/storage/docs/gsutil/addlhelp/Filenameencodingandinteroperabilityproblems#using-unicode-filenames-on-mac-os
思路:
-
由于mac的文件名编码: UTF-8-MAC, 所以如果
dialog.showOpenDialog
, 拿到的文件名就已经无法处理了. -
尝试下这个项目: https://www.npmjs.com/package/iconv-utf-8-mac, 果然看上去不靠谱, 就是不靠谱.
-
blog在这里: http://joker1007.hatenablog.com/entry/20110723/1311406670
-
iconv貌似不行: https://github.com/ashtuchkin/iconv-lite
必须要参考官网
- fs.readdir(), https://github.com/nodejs/node/issues/3519
- string2.normalize(‘NFD’), 没有卵用: https://github.com/nodejs/nodejs.org/blob/master/locale/en/docs/guides/working-with-different-filesystems.md
- php: filename = unicodedata.normalize(‘NFC’, unicode(filename, ‘utf-8’)).encode(‘utf-8’) : https://stackoverflow.com/questions/9757843/unicode-encoding-for-filesystem-in-mac-os-x-not-correct-in-python
- 命令行解决: https://stackoverflow.com/questions/12147410/different-utf-8-signature-for-same-diacritics-umlauts-2-binary-ways-to-write
- sync -a –iconv=utf-8-mac,utf-8 localdir/ mynas:remotedir/ https://serverfault.com/questions/397420/converting-utf-8-nfd-filenames-to-utf-8-nfc-in-either-rsync-or-afpd
结论: 很令人郁闷, 没有搞定这个, 暂时hold了….. 不过, php的库肯定是能搞定的. 目前nodejs没有对应的库而已.