// 4. If chunkPromise is fulfilled with an object whose done property is false
// and whose value property is a Uint8Array object, run these steps:
if(!chunk.done&&chunk.valueinstanceofUint8Array){
chunks.push(chunk.value);
// TODO: (only) If roughly 50ms have passed since last progress
{
constsize=chunks.reduce((p,i)=>p+i.byteLength,0);
constev=newProgressEvent("progress",{
loaded:size,
});
fr.dispatchEvent(ev);
if(fr.onprogress!==null){
fr.onprogress(ev);
}
}
chunkPromise=reader.read();
}// 5 Otherwise, if chunkPromise is fulfilled with an object whose done property is true, queue a task to run the following steps and abort this algorithm:
//If fr’s state is not "loading", fire a progress event called loadend at fr.
//Note: Event handler for the error event could have started another load, if that happens the loadend event for this load is not fired.
if(fr.readyState!==FileReader.LOADING){
constev=newProgressEvent("loadend",{});
fr.dispatchEvent(ev);
if(fr.onloadend!==null){
fr.onloadend(ev);
}
}
break;
}
}
}
classFileReaderextendsEventTarget{
error=null;
onabort=null;
onerror=null;
onload=null;
onloadend=null;
onloadstart=null;
onprogress=null;
readyState=FileReader.EMPTY;
result=null;
aborting=false;
constructor(){
super();
}
abort(){
// If context object's state is "empty" or if context object's state is "done" set context object's result to null and terminate this algorithm.
if(
this.readyState===FileReader.EMPTY||
this.readyState===FileReader.DONE
){
this.result=null;
return;
}
// If context object's state is "loading" set context object's state to "done" and set context object's result to null.
if(this.readyState===FileReader.LOADING){
this.readyState=FileReader.DONE;
this.result=null;
}
// If there are any tasks from the context object on the file reading task source in an affiliated task queue, then remove those tasks from that task queue.
// Terminate the algorithm for the read method being processed.
this.aborting=true;
// Fire a progress event called abort at the context object.
constev=newProgressEvent("abort",{});
this.dispatchEvent(ev);
if(this.onabort!==null){
this.onabort(ev);
}
// If context object's state is not "loading", fire a progress event called loadend at the context object.