mafintosh / csv-parser

Streaming csv parser inspired by binary-csv that aims to be faster than everyone else
MIT License
1.41k stars 134 forks source link

on('headers') not showing "0" as headers but in on('data') without headers values are shown with "0" headers #209

Closed sharmapr25 closed 2 years ago

sharmapr25 commented 2 years ago

Csv sample

name
Niru
Sangam
Gopal,
Mansa

Expected Behavior

There is a comma(,) after Gopal in sample csv that will get consider as different header except name. According to logic it will place it under "0" header. For .on('headers') event it should return all headers with '0' also Or it should throw invalid csv file error.

Actual Behavior

There is a comma(,) after Gopal in sample csv. on headers event it is giving only name as header but on data event it is giving row of Gopal and Mansa with "0" header.

How Do We Reproduce?

 fs.createReadStream(file.path, 'utf8')
  .pipe(csv())
.on('headers', headers => {
   console.log('headers are ', headers) 
  })
.on('data', (row) => {
  console.log('row are: ', row)  
 }

OUTPUT

headers are [name]
row are: {"name": "Niru"}
row are: {"name": "Sangam"}
row are: {"0": "Gopal"}
row are: {"0": "Mansa"}
sharmapr25 commented 2 years ago

This issue is fixed in latest version 3.0.0. fix: losing all headers after a broken line But now will add External logic to keep it working with node v8.17.0(as support for node 8 is not there with new version)