`option.to` breaks the stream and exits the program
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 4.3k
- Forks
- 299
- Avg merge
- 16h 19m
- Merged PRs (30d)
- 1
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the promises example and the provided reproduction, then inspect how csv-parse handles the to and to_line options together with Node.js stream completion. Confirm the behavior with the sample CSV and ensure await finished(parser) returns so the logs and assertion execute with the two expected records.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100