import * as fs from 'fs-extra' ; import * as path from 'path' ; import * as os from 'os' ; import { v4 as uuidv4 } from 'uuid' ; import { from , map , Observable } from 'rxjs' ; export const createTempFile$ = ( fileName ) : Observable < string > => { const filePath = path . join ( os . tmpdir ( ) , uuidv4 ( ) , fileName ) ; return from ( fs . ensureFile ( filePath ) ) . pipe ( map ( ( ) => filePath ) ) ; } ; export const writeStreamToFile = ( readableStream , writeStream ) : Promise < boolean > => { return new Promise ( ( resolve , reject ) => { readableStream . pipe ( writeStream ) ; let error = null ; writeStream . on ( 'error' , ( err ) => { error = err ; writeStream . close ( ) ; reject ( err ) ; } ) ; writeStream . on ( 'close' , ( ) => { if ( ! error ) { resolve ( true ) ; } } ) ; writeStream . on ( 'finish' , ( ) => { if ( ! error ) { resolve ( true ) ; } } ) ; } ) ; } ;