title: Trouble with the "File API: Directories and System" in Google Chrome
body: <p>Having read <a href="http://www.thecssninja.com/javascript/filesystem" rel="nofollow">this article</a> on using the HTML5 File System API in Google Chrome, I decided to have a go at incorporating it into a packaged web application.</p>
  
  <p>Using the notes and supplied code as a guide, I've put together a rather lengthy script as follows:</p>
  
  <pre><code>var FSA = FSA || {};
  var fsys, root, fileReader, dropReader, dropContainer, btn = [];
  window.addEventListener("load", function () {
      window.requestFileSystem(PERSISTENT, 5242880 /* ~5MB */, function(fs) {
          fsys = fs;
          root = fsys.root;
      }, FSA.error);
  });
  function createFile(path) { 
      root.getFile(path, {create:true, exclusive:true}, function() {
          console.log(path+ " file created"); 
      }, FSA.error); 
  };
  function saveFile(name, data, mimetype) {
      var e = this || null;
      name = name || e.target.name;
      data = data || e.target.result;
      mimetype = mimetype || e.target.type;
      root.getFile(name, {create: true}, function(fileEntry) {
          fileEntry.createWriter(function(writer) {
              writer.onwrite = function(e) {
                  console.log(name + ' written successfully to filesystem.');
                  FSA.getFile(name);
              };
              writer.onerror = function(e) {
                  console.log('Write failed: ' + e);
              };
              var bb = new BlobBuilder();
              bb.append(data);
              writer.write(bb.getBlob(mimetype));
          });
      }, FSA.error);
  };
  function openFile(file, fileTarget) {
      root.getFile(file.name, null, function(entry) {
          entry.file(function(file) {
                  reader = new FileReader();
                  reader.filename = file.name;
                  reader.onload = function(e) {
                      fileTarget = e.target.result;
                  };
                  reader.readAsText(file);
          }, FSA.error);
      }, FSA.error);
  };
  </code></pre>
  
  <p>And, to an extent, it seems to work. I can use the createFile function to create a file, and I can use the saveFile function to save a file. I cannot, however, seem to use the openFile function, and all three functions return the following error in the JavaScript console:</p>
  
  <pre><code>Uncaught TypeError: Cannot call method 'getFile' of undefined
  </code></pre>
  
  <p>I believe the problem has to do with the variable <code>root</code>, but I may be wrong.</p>
  
  <p>As this is a new API, and a draft spec at that, there's very little documentation available to help solve this issue.</p>
  
  <p>Would anyone be able to point out the problem(s), and, if so, contribute a solution?</p>
  
  <p>Thanks for your help.</p>
  
  <p><strong>EDIT:</strong> I'm using "10.0.639.0 canary build", so I believe that my browser should allow the API to be used in extensions.</p>