Skip to content

Instantly share code, notes, and snippets.

@mwbrooks
Created January 16, 2014 22:22
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 mwbrooks/8464659 to your computer and use it in GitHub Desktop.
Save mwbrooks/8464659 to your computer and use it in GitHub Desktop.
Read config.json with the Web File API
function readFile(filepath, callback) {
window.requestFileSystem(
LocalFileSystem.PERSISTENT,
0,
function(fileSystem) {
fileSystem.root.getFile(
filepath,
null,
function gotFileEntry(fileEntry) {
fileEntry.file(
function gotFile(file){
var reader = new FileReader();
reader.onloadend = function(evt) {
callback(null, evt.target.result); // text
};
reader.readAsText(file);
},
function(error) {
callback(error);
}
);
},
function(error) {
callback(error);
}
);
},
function(error) {
callback(error);
}
);
}
// use it
readFile('config.json', function(e, text) {
var config = (text) ? JSON.parse(text) : {};
console.log(config.URL);
})
@brianleroux
Copy link

man, we REALLY need to create the Hi5 lib + @davejohnson

@davejohnson
Copy link

ha no doubt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment