Created
April 1, 2012 00:32
-
-
Save ishiduca/2270042 to your computer and use it in GitHub Desktop.
convert shift_jis -> utf8 :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 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