I have this error while "piping" a file in node:
events.js:160
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at exports._errnoException (util.js:1022:11)
at Pipe.onread (net.js:569:26)
Here is my code:
var json_file = fs.createWriteStream(jsonFile),
processes = 0,
read_ended_flag = false,
converter = new Converter(params);
let read_csv_file = fs.createReadStream(csvFilePath);
// For each csv line, we get a json doc
converter.on('record_parsed', jsonObj => {
processes++;
json_file.write(JSON.stringify(jsonObj) + '\n', () => {
processes--;
if(read_ended_flag && processes == 0){
json_file.end();
callback();
}
});
});
converter.on('end_parsed', () => {
read_ended_flag = true;
});
read_csv_file
.pipe(converter);
I tried to catch error using this or this, but it still the same. This bug only comes while working with small files ( > 100 lines ).
Is it because that the read stream is closed before writing in the new file ?
Many thanks for any tips & helps !
via googirl
No comments:
Post a Comment