Last active
August 29, 2015 13:55
-
-
Save hanksudo/8701495 to your computer and use it in GitHub Desktop.
Read data line by line and turn in to JSON
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 fs = require('fs'); | |
var readline = require('readline'); | |
var stream = require('stream'); | |
var instream = fs.createReadStream('test.txt', 'utf8'); | |
var outstream = new stream; | |
var rl = readline.createInterface(instream, outstream); | |
var obj = {} | |
rl.on('line', function (line) { | |
var lines = line.split(' '); | |
obj[lines[0]] = lines[1]; | |
}); | |
rl.on('close', function() { | |
console.log(JSON.stringify(obj)); | |
}); |
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
{ | |
"1": "中文", | |
"2": "or", | |
"3": "&&", | |
"4": "abc", | |
"5": "CD" | |
} |
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
1 中文 | |
2 or | |
3 && | |
4 abc | |
5 CD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment