Created
April 30, 2014 02:41
-
-
Save mkuklis/f2397953e8d7edce87fd to your computer and use it in GitHub Desktop.
filestorage
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 storage = { | |
init: function (success, error) { | |
window.requestFileSystem(PERSISTENT, 100 * 1024 * 1024, success, error); | |
}, | |
write: function (fileName, content, success, error) { | |
this.init(function (fs) { | |
fs.root.getFile(fileName, { create: true }, function (fileEntry) { | |
fileEntry.createWriter(function (fileWriter) { | |
fileWriter.onwriteend = callback; | |
fileWriter.onerror = error; | |
fileWriter.write(content); | |
}, error); | |
}, error); | |
}, error); | |
}, | |
read: function (fileName, callback, error) { | |
this.init(function (fs) { | |
fs.root.getFile(fileName, {}, function (fileEntry) { | |
fileEntry.file(function (file) { | |
var reader = new FileReader(); | |
reader.onloadend = function (e) { | |
callback(this.result); | |
}; | |
reader.onerror = error; | |
reader.readAsText(file); | |
}, error); | |
}, error); | |
}, error); | |
}, | |
remove: function (fileName, success, error) { | |
this.init(function (fs) { | |
fs.root.getFile(fileName, { create: false }, function (fileEntry) { | |
fileEntry.remove(success, error); | |
}, error); | |
}, error); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment