This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Description
ran into the following issue. i'm creating a transform stream that "truncates" the source stream. here's an example:
util.inherits(Truncate, Stream.Transform)
function Truncate() {
this.count = 0
}
Truncate.prototype._transform = function (doc, enc, cb) {
if (this.count++ < 10) {
this.push(doc)
cb()
} else {
this.push(null)
cb()
}
}
ideally, once this.push(null)
is called, the transform stream should be considered "finished" and ._transform()
shouldn't be called anymore. however, this isn't the case as ._transform()
will continued to be called, and you'll get cannot push after EOF
due to additional .push(null)
s. to compensate, you'll have to keep track using some sort of this.ended
flag.
implementation might by iffy though if you're piping. not sure if the source stream should unpipe on dest.on('end')
or just continue writing and have the transform stream discard the data (which is what you'd do right now, anyways). i'm also not sure if and when the finish
event would occur in this case. would also be nice if there were consistent stream.destroy()
semantics.