node-tutorial icon indicating copy to clipboard operation
node-tutorial copied to clipboard

node的GBK转UTF8问题

Open Wscats opened this issue 8 years ago • 0 comments

GBK转UTF8

借助于iconv-lite模块

var fs = require("fs");
var iconv = require('iconv-lite');
var buffer = Buffer.from(fs.readFileSync('./703533.txt', {encoding: 'binary'}), 'binary');
var text = iconv.decode(buffer, 'GBK'); //使用GBK解码
console.log(text);

参考文档

Node.js环境中使用GBK编码

Wscats avatar Jan 25 '18 09:01 Wscats