Last active
May 7, 2019 05:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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