[Disclaimer: This is my very first shot at Node (I am mostly a Clojure guy)]
I am parsing and transforming a CSV file with node-csv. The transform happens with IO over the wire and I wrapped the callback with a async/await construct.
const in_stream = fs.createReadStream('test-data')
const out_stream = fs.createWriteStream('test-output')
const parse = csv.parse({ delimiter: "\t", quote: false })
const transform = csv.transform(async (row) => {
await translate(row[1], { from: 'en', to: 'fr' })
.then(res => { row[1] = res.text})
console.log(row) // this shows that I succesfully wait for and get the values
return row
})
const stringify = csv.stringify({
delimiter: ';',
quoted: true
})
in_stream.pipe(parse).pipe(transform).pipe(stringify).pipe(out_stream)
It appears that the stream ends before the values are piped out of the transformer.
How do you deal with delayed values in streams in Node.js? I am obviously getting it wrong…
(I can provide a dummy CSV file if it helps)