Skip to content

exos/CoFS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CoFS

Manage the HTML 5 File API like a Sir.

Ventages

  • Callbacks like Node.js (err, result)
  • Use Buffer (No encoding problem, binaries easy)
  • AMD (CommonJS, RequireJS, etc)
  • Works with Cordova/Phonegap/ionic

Dependencies

Instalation

$ bower install cofs

Usage

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'));

});

API

CoFS (Object)

new CoFS([options]);

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

CoFS.noConflict()

Returns CoFS object and restore the var CoFS to back definition.

~CoFS (Instance)

~CoFs.on(eventName, callback)

Subcribe callback to event.

~CoFS.once(eventname, callback)

Like on, but the callback only runs once time.

~CoFS.getFileSystem([options], callback)

Get a FileSystem instance.

Options can be:

  • fs: Type of filesystem, by default is PERSISTENT

~CoFS.getDirectory(dirName, [options], callback)

Get DirectoryEntry, the options are passed to the natie API, see this article.

~CoFS.getFileEntry(fileName, [options], callback)

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) {
        //...
    });
});

~CoFS.readFromFileObject(file, callback)

Read a file from a native File instance.

~CoFS.readFromFileEntry(fileEntry, callback)

Read a file from a native FileEntry object.

~CoFS.readFile(file, callback)

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.

~CoFS.writeFile(fileName, data, [encoding], callback)

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.

Development environment

You needs:

First clone the repo (this or your fork)

$ git clone https://github.com/exos/CoFS.git

Install the cli-tools:

$ sudo npm install -g bower grunt-cli 

Install dependencies

$ npm install
$ bower install

Check if you can build, etc:

$ grunt

Grunt tasks

  • check: Check the code with JSHint
  • build: Build the dist CoFS.js file minified and ready to use

Contrib

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

About

Class to manage HTML5 File API like.

Resources

Stars

Watchers

Forks

Packages

No packages published