Question

I am trying to create a file using the File system API..i googled and i get a code

function onFs(fs) {

  fs.root.getFile('log.txt', {create: true, exclusive: true},
      function(fileEntry) {
           fileEntry.getMetaData(function(md) {
            }, onError);

      },
      onError
  );
}

window.requestFileSystem(TEMPORARY, 1024*1024 /*1MB*/, onFs, onError);

can any one say what is the fs which is passed as function argument..

Please refer me a good example...

Was it helpful?

Solution

fs is a javascript object that allows you to make "system-like" level calls to a virtual filesystem.

So for instance you can use the fs object to create/get a reference to a file in the virtual filesystem with fs.root.getFile(...). The third argument (in your case, the following lines of code from your above snippet) in the .getFile(...) method happens to be a callback for successful obtaining of a file reference.

function(fileEntry) {
       fileEntry.getMetaData(function(md) {
        }, onError);
}

That file reference (in your case it is called fileEntry) can have various methods called such as .createWriter(...) for writing to files, .file(...) for reading files and .remove(...) for removing files. Your method calls .getMetaData(...) which contains a file size and modification date.

For more specifics as well as some good examples on the html5 file-system api you may find the following article helpful Exploring the File-System API

The location of the files differs on the browser, operating system and storage type (persistent vs. temporary) but the following link has served to be quiet useful as well Chrome persistent storage locations

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top