import {from, of} from 'rxjs' import {map, tap} from 'rxjs/operators' import readChunk from 'read-chunk' import {getSize} from './get-size' const chunkSize = Math.pow(2, 22) const progress = (context: any) => from(getSize(context)()) .pipe(map((size: any) => (context.position / size) * 100)) .pipe(tap((progress: number) => context.onProgress(progress))) .toPromise() export const getNext = (context: any) => async () => of(readChunk.sync(context.path, context.position, chunkSize)) .pipe(tap((chunk: any) => context.position += chunk.length)) .pipe(tap(() => context.onProgress && from(progress(context)))) .toPromise()