Skip to content

Really just some syntactic sugar on top of the W3C FileSystem API, but it's also nice to use. Only works on Google Chrome.

Notifications You must be signed in to change notification settings

mtaufen/pFS-micro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

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.

About

Really just some syntactic sugar on top of the W3C FileSystem API, but it's also nice to use. Only works on Google Chrome.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published