summera / chromestore.js

Simple filesystem API wrapper for Chrome

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reading content of a previously stored text (JSON) file.

alexKleider opened this issue · comments

Once data (in my use case: JSON text) is stored by chromestore.js on the local (client) machine, what is the mechanism of subsequently reading it for further use by local javascript routines? TIA Alex

Hey Alex!

chromestore.js getFile method returns a FileEntry object to the callback. FileEntry represents a file in a filesystem. Once you receive the FileEntry you can then read it using a FileReader. For example:

cs.getFile('myfile.json', {}, function(fileEntry) {
    fileEntry.file(function(file) {
       var reader = new FileReader();

       reader.onloadend = function(e) {
         // do something with data here
         var myData = this.result; 
       };

       reader.readAsText(file);
    }, errorHandler);
})

This is also how file writing is handled, however chromestore.js abstracts away some of these details by creating its own FileWriter object when you call the write method. We could do the same for FileReader, but at the time of making it was not needed. If you'd like to take a stab at it you are certainly welcome to!

http://www.html5rocks.com/en/tutorials/file/filesystem/ is great for learning about the filesystem API. Let me know if you have any issues/questions with this.