node-csv icon indicating copy to clipboard operation
node-csv copied to clipboard

Getting the column names before entering a for await loop

Open obones opened this issue 4 years ago • 1 comments

Hello,

Could it be possible to have the information about columns before starting the for await of loop. Here is what I would like to do:

const parser = sourceStream.pipe(csv_parse({ columns: true, info: true }));
if (expectedColumnsAreFound(parser))
    for await (const {record, info} of parser)
    {
        // process records
    }

Of course, I could move the columns validity test inside the loop, but it would be tested for all records which is a waste of computation time in huge files.

obones avatar Jul 08 '21 13:07 obones

I would set the columns to false, and handle it on my side. There is no current mechanism to handle this yet.

wdavidw avatar Jul 13 '21 08:07 wdavidw

Summer cleanup. Closing for lack of activity.

wdavidw avatar Aug 25 '23 13:08 wdavidw

Well, the request is still valid, just that I have not enough knowledge to offer a code change for this feature...

obones avatar Aug 25 '23 13:08 obones

I suggested to handle the feature in the application code. The feature might never be accepted in the parser. Note I could change my mind.

wdavidw avatar Aug 25 '23 13:08 wdavidw