Created
February 17, 2014 07:58
-
-
Save JacksonTian/9046532 to your computer and use it in GitHub Desktop.
utf8 => gbk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var iconv = require('iconv-lite'); | |
// 这里是utf8 | |
var str = '坑爹啊,都是国际项目了,编码居然还用gbk'; | |
console.log(new Buffer(str).length); | |
// 转换成gbk | |
var encoded = iconv.encode(str, 'gbk'); | |
fs.writeFile('gbk.txt', encoded, function () { | |
var buf = fs.readFileSync('gbk.txt'); | |
console.log(buf.length); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
被 sublime 坑了,原来早就转成功了,晕死