Created
October 20, 2014 10:48
-
-
Save welefen/447dffb497fb4260e67b to your computer and use it in GitHub Desktop.
Node.js里转码
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 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