Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Wrapper for File API that provide more user friendly way to work with files

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

JerkFS — simple wrapper for FileAPI

JerkFS is small js library that helps work with files in a simple and conscious way.

Usage

jerk.init( 5, 'PERSISTENT' ); // 5Mb of persistent storage

or

jerk.init( 5, 'TEMPORARY' ); // You may not to call this. By default will be created temporary storage with 1Mb

Files

Create new file if it not exist and write data that was passed as first argument:

jerk.file('test.txt').write('some text', function( result, file ){
    if( !result ){
        console.log( file.error, file.message );
        return;
    }

    file.read(function( result, file ){
      // result
    });
});

Add data to end of file:

jerk.file('test.txt').append('another some text', function( result, file ){
    // result and errObj the same as above
});

Read content of the file or throw error if it doesn't exist:

jerk.file('test.txt').read(function( result, file ){
    console.log(result);
});

Read content of the file and return as DataURI:

jerk.file('test.txt').toDataURI(function( result, file ){
    console.log(result);
});

Get url of the file:

jerk.file('test.txt').toURL(function( result, file ){
    console.log(result);
});

Remove file:

jerk.file('test.txt').remove(function( result, file ){
    console.log(result); // true or false
});

Write data from remote file (it will work only if script hosted on same domain or if server allow for cross-domain XHR):

jerk.file('test.txt').writeFromRemoteFile('http://example.com/index.html', function( result, file ){
    if( !result ){
        console.log( file.error, file.message );
    }
});

Directories

Read dir entries:

var file = 'test.txt', callback = function(){};

jerk.dir('/').read(function( result, dir ){
  // result — array with entries

  if( !result ){
    return;
  }
  for( var i=0, l=result.length; i<l; i++ ){
    if( result[i].isFile && result[i].name == file ){
      jerk.file( result[i].fullPath ).read(callback);
    }
  }
});

Remove directory recursively:

jerk.dir('/').remove(function( result, errObj ){
  if( !result ){
    console.log( errObj.error, errObj.message );
  }
});
Something went wrong with that request. Please try again.