-
Notifications
You must be signed in to change notification settings - Fork 281
Open
Description
Describe the bug
Using csv-parse package to parse a readable stream. Basically this example from your documentation. Introducing the to or to_line option seems to exit the stream without executing anything after await finished(parser); in line 27 below:
import assert from 'assert'
import fs from 'fs'
import os from 'os'
import { parse } from 'csv-parse'
import { finished } from 'stream/promises'
// Prepare the dataset
await fs.promises.writeFile(
`${os.tmpdir()}/input.csv`,
['a,b,c', '1,2,3', '3,4,5'].join('\n')
)
// Read and process the CSV file
const processFile = async () => {
const records = []
const parser = fs.createReadStream(`${os.tmpdir()}/input.csv`).pipe(
parse({
to: 2, // <-- add this option
})
)
parser.on('readable', function () {
let record
while ((record = parser.read()) !== null) {
// Work with each record
records.push(record)
}
})
await finished(parser)
// nothing gets executed after this
console.log(records) // <-- this does not print anything
return records
}
// Parse the CSV content
const records = await processFile()
console.log(records) // <-- this doesn't get executed
// Validate the records
assert.deepStrictEqual(records, [
['a', 'b', 'c'],
['1', '2', '3'],
])To Reproduce
The example is provided in the description above.
Additional context
Add any other context about the problem here.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels