import { PureEffect } from '@typed/effects' ; import { Either } from '@typed/either' ; import { Future } from '@typed/future' ; import { ArgsOf } from '@typed/lambda' ; import { createReadStream } from 'fs' ; export function * readFile ( ... args ) { return yield Future . create < unknown , Error , Buffer > ( ( reject , resolve ) => { const buffers = [ ] ; const stream = createReadStream ( ... args ) ; stream . on ( 'data' , ( data ) => buffers . push ( data ) ) ; stream . on ( 'error' , reject ) ; stream . on ( 'close' , ( ) => resolve ( Buffer . concat ( buffers ) ) ) ; return { dispose ( ) { stream . close ( ) ; } , } ; } ) ; }