@ -10,3 +10,7 @@ __Why does Promistreams not have Duplex streams?__ Because they're surprisingly
Aside from that, they are also just difficult to work with. Developers routinely get tripped up by the difference between a Duplex and a Transform stream, and it's much simpler to reason about your streams code when a separate readable and writable stream don't pretend to be a single stream when they're really not.
--
Things to document:
- "Cannot read from a partial pipeline; maybe you forgot to specify a source stream?" means that the stream you thought was readable/writable is actually a transform stream that's internally wired up to something else, and you should use the explicit fromReadable/fromWritable methods in that case. The adapter library cannot (currently) detect it, and wiring this up wrong can result in strange behaviour and phantom values.
@ -90,14 +90,18 @@ function fromWritable(stream) {
// NOTE: The use of `var` is intentional, to make hoisting possible here; otherwise we'd have a broken cyclical reference
varwritable=wireUpWritableInterface(stream,{
onClose:()=>{
onEnd:()=>{
debugWritable(`Underlying stream has reported a close event (upstreamHasEnded = ${upstreamHasEnded})`);
if(!upstreamHasEnded){
convertedStream.abort(true);
debugWritable(`Issuing happy abort on converted stream`);
convertedStream.abort(true,mostRecentSource);
}
},
onError:(error)=>{
// Make sure we notify the pipeline, if any, by passing in the most recent source stream that we've seen.
convertedStream.abort(mostRecentSource,error);
debugWritable(`Issuing error abort on converted stream due to: ${error.message}`);
convertedStream.abort(error,mostRecentSource);
}
});
@ -133,6 +137,7 @@ function fromTransform(stream) {
if(endHandled){
// NOTE: This logic exists at the start, not in the upstream EndOfStream handling code, because any number of buffer reads may be required before the wrapped Node stream can be closed
// NOTE: The push-buffer will automatically produce EndOfStream markers once the buffer has run out and the underlying stream has closed, so long as we're using the wireUpReadableInterface function
// FIXME: Refactor this design to request-matcher instead?