Last active
October 2, 2019 16:30
-
-
Save akirattii/235c7763f9c9b75684f766cf069b1144 to your computer and use it in GitHub Desktop.
NodeJS: Shift_JISな半角カナのファイルを一行づつ読み込んで内容を正常に出力
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
const fs = require("fs"); | |
const readline = require('readline'); | |
const iconv = require('iconv-lite'); | |
const readStream = fs.createReadStream("./shift_jis.txt", { encoding: "binary" }); | |
const rl = readline.createInterface(readStream, {}); | |
rl.on('line', function(line) { | |
// Shift_JIS => unicode: | |
console.log("line:", iconv.decode(new Buffer(line, "binary"), "Shift_JIS")); | |
}).on('close', function() { | |
console.log("close"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment