Skip to content

[BUG] writeToStream / writeToPath emits empty output following empty rows #503

@robations

Description

@robations

Describe the bug
When writing to a stream with an empty row and one or more rows with data, instead of writing the rows provided, writeToStream and writeToPath emits empty rows for each line. Not sure if intended but this seems to be a change in behaviour from v2 and feels like an unexpected outcome.

It might be slightly non-standard, but I'm working with a CSV file where the number of columns may change throughout the file.

Parsing or Formatting?

  • [ x] Formatting
  • Parsing

To Reproduce
Steps to reproduce the behavior:

// test.ts
import {writeToPath} from "fast-csv";

writeToPath("space-oddity.csv", [[], ["this", "should", "be", "written?"]], {headers: false})
    .on("finish", () => {
        console.log("done");
        process.exit();
    });
ts-node test.ts && cat space-oddity.csv

The same thing happens with writeToStream.

Expected behavior
Expected output:


this,should,be,written?

Screenshots
n/a

Desktop (please complete the following information):

  • OS: MacOS
  • OS Version 10.15.6
  • Node Version 12.18.3

Additional context
Let me know if you need any more info. I tried to step through the source code with the debugger, but the line numbers were pretty mangled so it wasn't clear what was happening when.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions