@@ -109,7 +109,7 @@ async function* fromReadable(val) {
109
109
yield * Readable . prototype [ SymbolAsyncIterator ] . call ( val ) ;
110
110
}
111
111
112
- async function pump ( iterable , writable , finish ) {
112
+ async function pump ( iterable , writable , finish , opts ) {
113
113
let error ;
114
114
let onresolve = null ;
115
115
@@ -153,7 +153,9 @@ async function pump(iterable, writable, finish) {
153
153
}
154
154
}
155
155
156
- writable . end ( ) ;
156
+ if ( opts !== false ) {
157
+ writable . end ( ) ;
158
+ }
157
159
158
160
await wait ( ) ;
159
161
@@ -227,6 +229,7 @@ function pipelineImpl(streams, callback, opts) {
227
229
const stream = streams [ i ] ;
228
230
const reading = i < streams . length - 1 ;
229
231
const writing = i > 0 ;
232
+ const end = reading || opts ?. end !== false ;
230
233
231
234
if ( isNodeStream ( stream ) ) {
232
235
finishCount ++ ;
@@ -282,14 +285,17 @@ function pipelineImpl(streams, callback, opts) {
282
285
then . call ( ret ,
283
286
( val ) => {
284
287
value = val ;
285
- pt . end ( val ) ;
288
+ pt . write ( val ) ;
289
+ if ( end ) {
290
+ pt . end ( ) ;
291
+ }
286
292
} , ( err ) => {
287
293
pt . destroy ( err ) ;
288
294
} ,
289
295
) ;
290
296
} else if ( isIterable ( ret , true ) ) {
291
297
finishCount ++ ;
292
- pump ( ret , pt , finish ) ;
298
+ pump ( ret , pt , finish , { end } ) ;
293
299
} else {
294
300
throw new ERR_INVALID_RETURN_VALUE (
295
301
'AsyncIterable or Promise' , 'destination' , ret ) ;
@@ -302,7 +308,7 @@ function pipelineImpl(streams, callback, opts) {
302
308
}
303
309
} else if ( isNodeStream ( stream ) ) {
304
310
if ( isReadableNodeStream ( ret ) ) {
305
- ret . pipe ( stream ) ;
311
+ ret . pipe ( stream , { end } ) ;
306
312
307
313
// Compat. Before node v10.12.0 stdio used to throw an error so
308
314
// pipe() did/does not end() stdio destinations.
@@ -314,7 +320,7 @@ function pipelineImpl(streams, callback, opts) {
314
320
ret = makeAsyncIterable ( ret ) ;
315
321
316
322
finishCount ++ ;
317
- pump ( ret , stream , finish ) ;
323
+ pump ( ret , stream , finish , { end } ) ;
318
324
}
319
325
ret = stream ;
320
326
} else {
0 commit comments