node.jsãMacã§åãããéã«ã軽ãããã£ãã®ã§æ¸ãã¦ããã
UTF-8ã®æåã³ã¼ãã§ãã¡ã¤ã«ã«ã¢ã¯ã»ã¹ãããã¨ããå ´åã
MacOSã¯å
é¨ã§åæã«å¤æãã¦ãUTF-8-MACã¨ãã¦ãã¡ã¤ã«ã«ã¢ã¯ã»ã¹ããã®ã§ã
æèããã«ãã¡ã¤ã«ãæä½ã§ããã
ä¸æ¹ã§ããã¡ã¤ã«åãåå¾ãããã¨ããã¨ãUTF-8-MACã§æ»ã£ã¦ããã
lsã³ãã³ããæã¤ã¨ã¿ã¼ããã«ã«ãã£ã¦ã¯åãããããã
ã¾ããMacã使ã£ã¦ãã人ã«ã¯ãå½ããåã®è©±ã
UTF-8-MACã§å°ããã¨
ããã¯ç´æ¥ãã¡ã¤ã«ãããã£ã¦ãéã«ã¯ä½ãå°ããªãã®ã ãã
ç¹å®ã®ãã£ã¬ã¯ããªä»¥ä¸ã®ãã¡ã¤ã«ä¸è¦§ãä½ãããã®DBã«çªã£è¾¼ãã¨ããå¦çãããå ´åã
ä½ãèããã«DBã«ãã¡ã¤ã«åãæ¸ãè¾¼ãã¨ãUTF-8-MACã§æ¸ããããã¨ã«ãªãã
ããããDBã¯MacOSããã£ã¦ãããããã«ãåæã«UTF-8ãUTF-8-MACã«å¤æãããã¯ããªãã
ãªã®ã§ãã¦ã§ããã©ã¦ã¶çããå
¥åãããæååãå
ã«ã¯ã¨ãªãæ§ç¯ãã¦DBã«æããå ´åã
æåã³ã¼ãã®ãºã¬ã§è¦ã¤ããã¯ãã®ãã¼ã¿ãè¦ã¤ãããªãã¨ããå°ã£ããã¨ã«ãªãã
対ç
ãããããUTF-8-MACãªãã¦å½¢å¼ã§DBã«æ ¼ç´ãã¦ããã®ãè¯ããªãã
ãªã®ã§ãæ ¼ç´ããåã«ä¸è¬çãªUTF-8ã«å¤æãã¦ããã®ãæ®éã ããã
node.jsãªãnode-iconvã¨ããã©ã¤ãã©ãªãããã®ã§ããããå©ç¨ãããã
ãã ãä¸ã¤åé¡ãããã
UTF-8-MACã¯æ®éã®iconvã§ã¯å©ç¨ã§ããªãã
MacOSã®ããã«Appleãæãå ããiconvãå¿
è¦ã«ãªãã
node-iconvã«ã¯ãiconvã®ã½ã¼ã¹ãå梱ããã¦ããããããã³ã³ãã¤ã«ãã¦å©ç¨ããããã«ãªã£ã¦ããã
ããããããã使ã£ã¦ãã¾ãã¨UTF-8-MACã£ã¦ä½ã ãã¨æãããã
ãªã®ã§ãAppleã«ããUTF-8-MAC対å¿çãå©ç¨ããã
UTF-8-MAC対å¿çã¯ä»¥ä¸ããDLå¯è½ã
http://www.opensource.apple.com/tarballs/libiconv/
(ããã¤ã並ãã§ããããæ°åã大ããã®ãææ°)
以ä¸ã®ãããªæé ã§å¯¾å¿ããã
# ã¢ã¸ã¥ã¼ã«ãã¤ã³ã¹ãã¼ã« npm install iconv # ã¢ã¸ã¥ã¼ã«ã®ãã£ã¬ã¯ããªã«ç§»å cd node_modules/iconv # ã¤ã³ã¹ãã¼ã«æã«ã³ã³ãã¤ã«ãããã¢ã¸ã¥ã¼ã«ãåé¤ make clean # Appleçã®iconvãDLãã¦ãã½ã¼ã¹ã³ã¼ããåãåºããnode-iconvã®depsãã£ã¬ã¯ããªã«ç½®ã wget http://www.opensource.apple.com/tarballs/libiconv/libiconv-30.tar.gz tar xvzf libiconv-30.tar.gz mv libiconv-30/libiconv deps/
Makefileã以ä¸ã®æ§ã«ä¿®æ£ããã
--- Makefile.org 2011-07-23 16:22:06.000000000 +0900 +++ Makefile 2011-07-23 16:13:15.000000000 +0900 @@ -5,10 +5,10 @@ endif ifeq ($(NODE_INCLUDE_PATH),) - NODE_INCLUDE_PATH = $(NODE_PATH)/include/node + NODE_INCLUDE_PATH = $(NODE_PATH)/../../include/node endif -LIBICONV_DIR =deps/libiconv-1.13.1 +LIBICONV_DIR =deps/libiconv LIBICONV =$(LIBICONV_DIR)/lib/.libs/libiconv.a
NODE_INCLUDE_PATHãæ¸ãæãã¦ããã®ã¯ãnaveã§è¨å®ãããç°å¢å¤æ°NODE_PATHãã
Makefileã§æ³å®ããã¦ãããã£ã¬ã¯ããªæ§æã¨ãºã¬ã¦ããããã
å¾ã¯ãmakeã³ãã³ããå®è¡ããã°ãAppleçã®iconvãå©ç¨ããnode-iconvã¢ã¸ã¥ã¼ã«ãåºæ¥ãã
使ãæ¹ (CoffeeScript)
{Iconv} = require 'iconv' conv = new Iconv 'UTF-8-MAC', 'UTF-8' filename = conv.convert(filename).toString 'utf-8'
ã¾ããnode.jsã«éãããiconvç³»ã®ã¢ã¸ã¥ã¼ã«ãMacã§ä½¿ãæã¯ã
ä¼¼ããããªãã¨ããªãããããªãã£ã¦è©±ã