Skip to content

Instantly share code, notes, and snippets.

@JacksonTian
Created February 17, 2014 07:58
Show Gist options
  • Save JacksonTian/9046532 to your computer and use it in GitHub Desktop.
Save JacksonTian/9046532 to your computer and use it in GitHub Desktop.
utf8 => gbk
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);
});
@antife-yinyue
Copy link

The encoding option is ignored if data is a buffer. It defaults to 'utf8'.

@antife-yinyue
Copy link

被 sublime 坑了,原来早就转成功了,晕死

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment