Skip to content

Instantly share code, notes, and snippets.

@hubgit
Created December 12, 2021 13:19
Show Gist options
  • Save hubgit/79b7933a93de1aae5c5022c729a71819 to your computer and use it in GitHub Desktop.
Save hubgit/79b7933a93de1aae5c5022c729a71819 to your computer and use it in GitHub Desktop.
Transforming objects in a stream
import { Transform } from 'stream'
import inputStream from 'input-stream'
import outputStream from 'output-stream'
inputStream('input.csv')
.pipe(
Transform({
readableObjectMode: true,
writableObjectMode: true,
transform: (chunk, encoding, callback) => {
console.log(chunk)
callback(null, chunk)
},
})
)
.pipe(outputStream('output.ndjson'))
.on('finish', () => {
console.log('finished')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment