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

[HELP] Why does csv-parser skips headers with empty data? #181

Open abhishekdeshkar opened 3 years ago

abhishekdeshkar commented 3 years ago

I have a CSV file which I'm reading it row wise. There are some rows which are empty but columns do exists.

The issue is that it doesn't read header name which has no data.

How do I read everything ?

function GetRows(headers)
{
    StoreHeaders = headers;

    StoreHeaders.forEach(header => {

        let WordsArray = [];
        let CurrentGroupName;

        fs.createReadStream('word_groups.csv')
        .pipe(csv())
        .on('data', (data) => {

            if(data[header])
            {

                WordsArray.push(data[header]);
                CurrentGroupName = header;

            }

        })
        .on('end', () => {
            console.log(CurrentGroupName);
        });
    });

}

fs.createReadStream('word_groups.csv')
.pipe(csv())
.on('headers', (headers) => {

    GetRows(headers);

});
SimonSimCity commented 3 years ago

Which version of this library are you using? Can you please share a sample of a csv file?

Maybe it is related to #151 which was introduced after 2.3.0 (the last version where the case described in #151 worked as expected).