Skip to content
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

Description

@phillip-odam

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions