Skip to content

Latest commit

 

History

History
46 lines (27 loc) · 1.47 KB

README.rdoc

File metadata and controls

46 lines (27 loc) · 1.47 KB

pFS-micro

This micro-library is ONLY for PERSISTENT local storage.

See this page for a brief overview of the API and the basis of this library. www.html5rocks.com/en/tutorials/file/filesystem/#toc-direntry

Usage:

To access the current filesystem for your app or create a new one (if none exist):

pFS.set(size_of_filesystem_in_bytes, callback_function(filesystem_object){ });

To create a new file or writeOver content in an existing file of the same name:

pFS.writeOver(filesystem_object, filename_string, data_string, callback_function(e){ });

Note: This will only write over the data in the file, it will not replace it. For example, if you had a file called ‘text.txt’ and it contained the string ‘awesomestring’, and you performed writeOver on it with a data_string of ‘str’, ‘text.txt’ would then contain ‘strsomestring’

To actually replace the contents of a file:

pFS.replaceContent(filesystem_object, filename_string, data_string, callback_function(e){ });

To read from a file:

pFS.readFrom(filesystem_object, filename_string, callback_function(e));

It is best to perform subsequent filesystem operations in the callback of pFS.set() like so:

pFS.set(2*1024*1024, function (fs) {
	pFS.writeOver(fs, 'data.txt', JSON.stringify(data), function (e) {
		pFS.readFrom(fs, 'data.txt', displayAccounts);
	});
});

Just be careful not to accidentally redefine ‘fs’ when doing things this way, or you wont be able to access your filesystem.