Answer the question
In order to leave comments, you need to log in
Node.js fs. How it is possible to modify the data in a stream?
Good day everyone, the essence of the problem is as follows, I parsed the bigdata and pushed the data to the file, I forgot that json objects should be separated by a comma, I wrote these crutches:
let fs = require('fs');
let writer = fs.createWriteStream('data_valid.json', {flags: 'w'});
let reader = fs.createReadStream('data.json',
{
flags: 'r',
encoding: 'utf8'
});
writer.on('finish', function () {
console.error('Запись выполнена успешно.');
});
reader.on('readable', function() {
let buf;
while ((buf = reader.read()) !== null) {
writer.write(buf+',');
}
});
Answer the question
In order to leave comments, you need to log in
And I want to ask what is the problem with just copying the file, you are not doing anything else.
Вы не завершаете поток записи и даже не флушаете его на диск, все данные остаются в оперативке и дохнут вместе с процессомreader.on('end', () => writer.end());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question