Write a file using the FileSystem API

I am trying to create a file using the file system API .. google and I get the 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 anyone say what fs is, which is passed as an argument to a function.

Please write me a good example ...

+4
source share
1 answer

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

So, for example, you can use the fs object to create / get a link to a file in the virtual file system using fs.root.getFile(...) . The third argument (in your case, the following lines of code from your above snippet) in the .getFile(...) method is a callback to successfully obtain a link to the file.

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

This file reference (called fileEntry in your case) can have various methods called .createWriter(...) for writing to files, .file(...) for reading files, and .remove(...) for deleting files . Your method calls .getMetaData(...) , which contains the file size and date modified.

For more details, as well as some good examples in the html5 file system, you can find the following useful article Exploring the File System API

The location of the files varies in browser, operating system and storage type (permanent or temporary), but the following link also served as a quiet, and chrome Chrome storage

0
source

All Articles