import type { Readable } from 'stream' ; import { pipeline , Writable } from 'stream' ; export const readStreamToCompletion = < T = any > ( stream ) => { return new Promise < T [ ] > ( ( resolve , reject ) => { const chunks = [ ] ; pipeline ( stream , new Writable ( { objectMode : true , write ( chunk , enc , done ) { chunks . push ( chunk ) ; done ( ) ; } , } ) , ( err ) => { if ( err ) { reject ( err ) ; } else { resolve ( chunks ) ; } } ) ; } ) ; } ;