mafintosh / csv-parser

Streaming csv parser inspired by binary-csv that aims to be faster than everyone else
MIT License
1.41k stars 134 forks source link

Support async, await grammar #182

Closed jopemachine closed 3 years ago

jopemachine commented 3 years ago

Feature Proposal

How about supporting async, await grammar like below way?

Option objects may be forwarded if necessary.

Feature Use Case

const readCsv = async (csvFilePath) => {
  const csvResult = []
  return new Promise((resolve, reject) => {
    try {
      fs.createReadStream(csvFilePath)
        .pipe(csv())
        .on('data', (data) => csvResult.push(data))
        .on('end', () => {
          resolve(csvResult)
        })
    } catch (e) {
      reject(e)
    }
  })
}

...

const csvArr = await readCsv(csvFilePath)
shellscape commented 3 years ago

Thanks for the suggestion. There are a bazillion packages on npm for promisifying streams, and a ton of variations on that theme. I'd recommend searching npm for the solution that fits you. At the moment, I'm going to make the call to decline the request for this package due to the availability of stream/promise solutions on npm.

TrySound commented 3 years ago

We use get-stream.

jopemachine commented 3 years ago

We use get-stream.

Thanks for letting me know!

it helps a lot :)