param { Array < Stream > } streams return { Promise < any > } import { pipeline , Writable , Readable } from 'stream' ; function isReadable ( stream ) { return 'read' in stream && typeof stream . read === 'function' ; } export async function createPromiseFromStreams < T > ( streams ) { let finalChunk ; const last = streams [ streams . length - 1 ] ; if ( ! isReadable ( last ) && streams . length === 1 ) { throw new Error ( 'A minimum of 2 streams is required when a non-readable stream is given' ) ; } if ( isReadable ( last ) ) { streams . push ( new Writable ( { objectMode : true , write ( chunk , enc , done ) { finalChunk = chunk ; done ( ) ; } , } ) ) ; } return new Promise ( ( resolve , reject ) => { pipeline ( ... streams , ( err ) => { if ( err ) return reject ( err ) ; resolve ( finalChunk ) ; } ) ; } ) ; }