objectMode piping?
yoshuawuyts opened this issue · 3 comments
Does pump handle object streams correctly? I'm having trouble getting it to work, e.g.
const through = require('through2')
const ndjson = require('ndjson')
cons pump = require('pump')
const rs = process.stdin
const ts = ndjson.parse()
const ws = through.obj(function (chunk, enc, cb) {
console.log(typeof chunk)
})
// this works fine
rs.pipe(ts).pipe(ws)
// => 'object'
// this turns objects back into strings
pump(rs, ts, ws)
// => 'string'
Any idea what's going on?
alright, so this seems to work:
pump(ts, ws)
return ts
This doesn't
return pump(ts, ws)
I think... I might have been doing something horribly wrong haha. E.g. assuming pump(stream1, stream2)
returns stream1
. Uh oh.
Not sure if it should behave that way tho, in my head pump
turns multiple streams into a single stream, being able to be passed around as if it were a single stream would make sense to me. Not sure if that would make sense to others.
pump works like pipe except it adds error handling and stream destruction on error. like pipe it returns the last stream argument. if you wanna convert all your streams into a single stream pipeline use pumpify
Oh god yeah I was confusing the two. Thanks a lot for responding ^^