This question is kind of awkward, so I'll just post my code and say what it's doing and what I want it to do.
var fs = require('fs');
var myReader = fs.createReadStream('file.tsv', {
flags: 'r',
encoding: 'UTF-8',
fd: null,
mode: 0666,
bufferSize: 64 * 1024,
autoClose: true
});
myReader.on('data', function(data){
var array = (array || data.split(/[\n]/));
// Parse and print array
})
This works completely fine as long as there's only one chunk, any more than that, and my data can or will get split in the middle of a line.
I'm trying to keep the same array, and append a new chunk to it. The code above doesn't represent an attempt at that, but I've tried a few with += and array.concat(data.split(/[\n]/)) and I've not had much success.
So how can I keep the same array for parsing, and just append the new data to it as becomes available?
Thank you.
Try this:
var t = "";
myReader = fs.createReadStream(file, {
flags: 'r',
encoding: 'UTF-8',
fd: null,
mode: 0666,
bufferSize: 128 * 1024,
autoClose: true
})
myReader.addListener("data", function (chunk) {
t += chunk;
})