Skip to content

Instantly share code, notes, and snippets.

@welefen
Created October 20, 2014 10:48
Show Gist options
  • Save welefen/447dffb497fb4260e67b to your computer and use it in GitHub Desktop.
Save welefen/447dffb497fb4260e67b to your computer and use it in GitHub Desktop.
Node.js里转码
var iconvLite = require('iconv-lite');
global.convertEncoding = function(str, encoding){
encoding = encoding || 'utf8';
if (encoding === 'utf8') {
return iconvLite.decode(new Buffer(str, 'binary'), 'gb2312');
}else{
return iconvLite.encode(str, 'gb2312').toString('binary');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment