Manage the HTML 5 File API like a Sir.
- Callbacks like Node.js (err, result)
- Use Buffer (No encoding problem, binaries easy)
- AMD (CommonJS, RequireJS, etc)
- Works with Cordova/Phonegap/ionic
- Buffer: http://github.com/anodynos/node2web_buffer
- Async.js: https://github.com/caolan/async
- eventemitter2 https://github.com/hij1nx/EventEmitter2
$ bower install cofs
var fs = new CoFS();
fs.readFile($('input[type="file"]').files[0], function (err, data) {
if (err) {
// Display, ignore, kills, love, etc
}
console.log("Data of file:" + data.toString('utf-8'));
});
CoFS object is a Class, options parameter is optional:
var fs = new CoFS();
Options can be:
- fs: Type of FileSystem request, by Default is PERSISTENT (see this page)
- logger: Callback for debug logger
Returns CoFS object and restore the var CoFS to back definition.
Subcribe callback to event.
Like on, but the callback only runs once time.
Get a FileSystem instance.
Options can be:
- fs: Type of filesystem, by default is PERSISTENT
Get DirectoryEntry, the options are passed to the natie API, see this article.
Get a FileEntry instance, from a path
The options are pass to the native API, but accept a root param for define a directory, for example:
var fs = new CoFS();
fs.getDirectory('data', function (err, directory) {
// ...
fs.getFileEntry('myFile.dat', { root: directory }, function (err, file) {
//...
});
});
Read a file from a native File instance.
Read a file from a native FileEntry object.
Identify the object passed and read a file, the first param cab be a File object, FileEntry object, or a String with the file path.
Write a file with the content of data, if data is a Buffer object, encoding is not expected, is data is a String, encoding is needed.
You needs:
$ git clone https://github.com/exos/CoFS.git
$ sudo npm install -g bower grunt-cli
$ npm install
$ bower install
$ grunt
- check: Check the code with JSHint
- build: Build the dist CoFS.js file minified and ready to use
You can contrib with:
- Use and testing it
- Reporting errors, ideas on Issues section
- Add or fixing code, fork this repo and send Pull Requests :)
- Fix documentation
- Donate :P BTC 14NvJxpQsxs4EK8MTq2rubTDwuy54uCesu