This repository was archived by the owner on Jun 28, 2021. It is now read-only.
This repository was archived by the owner on Jun 28, 2021. It is now read-only.
column headers do not appear to be used if from_line > 1 #321
Open
Description
When from_line greater than 1 and columns set to true the column headers aren't used as keys in the returned object from the read method.
Here's a test script used to look at the issue, are there more properties needing to be provided to parse so that each returned record includes the column headers?
"use strict";
const parse = require("csv-parse");
const fs = require("fs");
var csvParser = parse({
"delimiter": ",",
"quote": "\"",
"record_delimiter": "\n",
"from_line": 2,
"columns": true
});
var initialExecution = true;
csvParser.on("readable", function () {
if (initialExecution) {
initialExecution = false;
var record;
while (record = csvParser.read()) {
console.debug({ record: record });
console.debug(Object.keys(record));
break;
}
}
});
csvParser.on("error", function (err) {
console.error({ error: err });
});
var readStream = fs.createReadStream("**SOME-CSV**");
readStream.on("open", function () {
readStream.pipe(csvParser);
});
readStream.on("error", function (err) {
console.error({ error: err });
});
If from_line in the script above is changed from 2 to 1 all works as desired, but if 2 or greater the columns aren't autodetected. Is the idea that the skipped lines aren't even being considered as valid CSV ie. this parser can be used to pull out a CSV from a greater file that isn't a CSV?