Sunday, 11 June 2017

Mismatch data between input & output when using stream.write

I'm using csv-stringify to convert array object to string and append to csv file. I write 500 row but received 314 row in csv file?

Here is my codes:

    let stringifyOpts = { formatters: this.formatters }
  if (isFirstChunk) {
    stringifyOpts.header = true;
    stringifyOpts.columns = this.columnNames
  }

  let stringifier = csv.stringify(stringifyOpts);
  let writeStream = fs.createWriteStream(this.filePath, { flags: 'a' });
  stringifier.pipe(writeStream);
  //data.length = 500
  data.forEach(row => {
    stringifier.write(row);
  })
  stringifier.end();
  writeStream.end();

Thank for any advise!

Regards.



via pcuong

No comments:

Post a Comment