Skip to content

Instantly share code, notes, and snippets.

@yannisalexiou
Last active May 7, 2019 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yannisalexiou/46e374895a1a941dae227d94c2b37073 to your computer and use it in GitHub Desktop.
Save yannisalexiou/46e374895a1a941dae227d94c2b37073 to your computer and use it in GitHub Desktop.
This is a way to loop through FileReader by using th recursive function that reads the blob file.
var foo = new Blob(["Lorem ipsum dolor sit amet, consectetur adipiscing elit."], {
type: 'text/plain'
});
var bar = new Blob(["Sed tristique ipsum vitae consequat aliquet"], {
type: 'text/plain'
});
var arrayOfBlobs = [foo, bar];
var arrayIndex = 0;
function fileRead () {
var me = this;
if (this.arrayIndex < this.arrayOfBlobs.length) {
var reader = new FileReader();
function bindedOnload(event) {
console.log("bindedOnload called");
console.log("reader results: ", event.target.result);
this.arrayIndex++;
this.fileRead();
}
reader.onload = bindedOnload.bind(me);
reader.readAsText(this.arrayOfBlobs[arrayIndex]);
} else {
console.log("Finished");
}
}
fileRead();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment