Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Created April 1, 2012 00:32
Show Gist options
  • Save ishiduca/2270042 to your computer and use it in GitHub Desktop.
Save ishiduca/2270042 to your computer and use it in GitHub Desktop.
convert shift_jis -> utf8 :node.js
var Iconv, iconv, httpRequest;
httpRequest = require('httpclient').httpRequest;
Iconv = require('iconv').Iconv;
//iconv = new Iconv('SHIFT_JIS', 'UTF-8//TRANSLIT//IGNORE');
iconv = new Iconv('CP932', 'UTF-8//TRANSLIT//IGNORE');
function gsURL (uri) {
return function (_uri) {
if (_uri && _uri !== uri) uri = _uri;
return uri;
};
}
var client = {};
client.httpRequest = httpRequest;
client.URL = gsURL('http://a.encoding.shift_jis.src');
client.httpRequest(client.URL, function (response) {
var body = '';
response.on('error', function (e) {
console.log(e);
process.exit(1);
});
response.on('data', function (chunk) {
body += chunk;
});
response.on('end', function () {
console.log(iconv.convert(body).toString('utf8'));
//process.stdout.write(iconv.convert(body));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment