max-mapper / max-mapper/csv-write-stream

Awaiting writer.end() doesn't write to file

Open
#47 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
203
Forks
34
PR merge metrics
No merged PRs in 30d

Description

Awaiting writer.end() doesn't close the original filestream as of ^2.0.0.

eg.

await writer.end()
console.log(`finished: ${await csvtojson().fromFile(filepath).length}`)

sometimes throws Error: File does not exist.

I got around this issue by manually closing the filestream:

  const writer = csv_writer()
  const stream = fs.createWriteStream(csv_file)

  writer.pipe(stream)
  json_obj.forEach((row) => writer.write(row))
  writer.end()

  await new Bluebird((resolve) => {
    stream.on('close', resolve)
  })

Contributor guide

No contributing guide indexed for this repository

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 at the writer.end() entry point and reproduce the reported behavior with the await writer.end() and csvtojson().fromFile(filepath) example. Trace how the writer is piped to the original filestream; done means awaiting writer.end() reliably leaves the output file available without manually listening for the stream's close event.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.