adaltas / adaltas/node-csv

Missing header in output when input has only header

Open
#274 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
4.3k
Forks
299
Avg merge
16h 19m
Merged PRs (30d)
1

Description

Hi there,

The following code

const inputFilePath = 'test_in.csv';
const outputCsv = fs.createWriteStream('test_out.csv');

fs.createReadStream(inputFilePath)
    .pipe(csv.parse({ columns: true }))
    .pipe(csv.stringify({ header: true, quoted: true }))
    .pipe(outputCsv);

Gives the output I expect (output same as input, apart from the quotes) when the input has lines beyond the header, but gives an empty file instead when test_in.csv only contains a header. Is that expected? How can I force it to always dump the header to the output?

Many thanks in advance.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided test_in.csv/test_out.csv stream pipeline, especially csv.parse({ columns: true }) and csv.stringify({ header: true, quoted: true }), using an input containing only the header. Check the existing parser and stringifier tests for header-only behavior; done means the expected header output is documented or covered by a confirmed fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.