I need to return the value of tempVar but I can't figure out how to do this since it is the result of a callback. What is the correct way to handle something like this? I'm not really sure how to word this problem. I was hoping it would work by doing something like var tempReturned = readPWFile('filename.txt'); but that doesn't for obvious reasons even if I were to have a 'return' somewhere in the callback. My main goal is to return the results of a txt file to a variable. Can someone point me in the right direction?
function readPWFile(fileName) {
var tempVar;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileSystem.root.getFile(fileName, null, gotReadFileEntry, fail);
});
function gotReadFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);
}
function gotFile(file) {
readDataUrl(file);
}
function readAsText(file) {
var reader = new FileReader();
reader.onloadend = function (evt) {
tempVar = evt.target.result;
};
reader.readAsText(file);
}
}