import { Readable } from 'stream' ; export function bufferToStream ( buf ) { const readable = new Readable ( ) ; readable . _read = ( ) => { } ; readable . push ( buf ) ; readable . push ( null ) ; return readable ; } export async function streamToBuffer ( str ) { return await new Promise ( ( resolve , reject ) => { let data = [ ] ; str . on ( 'error' , reject ) . on ( 'data' , ( chunk ) => data . push ( chunk ) ) . on ( 'end' , ( ) => resolve ( Buffer . concat ( data ) ) ) ; } ) ; }