export class FileSource implements UnderlyingSource { fr : FileReader ; chunkSize : number = 1024 * 65 ; chunkStart : number = 0 ; loadedChunkCb : ( ) => void ; constructor ( private file ) { } start ( controller ) { this . fr = new FileReader ( ) ; this . fr . onload = ( e ) => { controller . enqueue ( this . fr . result ) ; this . loadedChunkCb ( ) ; this . loadedChunkCb = ( ) => { } ; } ; this . fr . onerror = e => { controller . error ( this . fr . error ) ; } ; } pull ( controller ) { if ( this . chunkStart <= this . file . size ) { this . fr . readAsArrayBuffer ( this . file . slice ( this . chunkStart , this . chunkStart + this . chunkSize ) ) ; this . chunkStart += this . chunkSize ; } else { controller . close ( ) ; } return new Promise < void > ( ( resolve , reject ) => { this . loadedChunkCb = resolve ; } ) ; } }