Skip to content

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

@clark-hive

Description

@clark-hive

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)
  })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions