-
-
Save dickeylth/11287064 to your computer and use it in GitHub Desktop.
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
fs.writeFileSync不支持 gbk ,得用 buffer 过渡一下