cordova-promise-fs
Wraps the Cordova File API in convenient functions (that return a Promise)
Are you entangled in a async callback mess to get even the simplest task done? Wait no longer -- here is cordova-promise-fs!
Getting started
bower install cordova-promise-fs
npm install cordova-promise-fs
cordova plugin add org.apache.cordova.file
cordova plugin add org.apache.cordova.file-transfer
Usage
Initialize & configuration
var CordovaFS = require('cordova-fs-promise');
var fs = CordovaFS({
persistent: true,
storageSize: 20*1024*1024,
concurrency: 3
Promise: require('promiscuous')
});
Note on concurrency: Concurrent uploads/downloads completely trash your mobile application. That's why I've put a concurrency limit on the number of downloads/uploads. Meteor sets this number on 30. In my experimental testing, I found 3 much more reasonable.
Browsing files
fs.exists(filename)
fs.file(filename)
fs.dir(path)
fs.list(path,optionString)
optionString = 'r'
optionString = 'd'
optionString = 'f'
optionString = 'e'
optionString = 'rfe'
Reading files
fs.read(filename)
fs.readJSON(filename)
fs.toUrl(filename)
fs.toInternalURL(filename)
fs.toDataURL(filename)
Writing files
fs.write(filename,data)
File operations
fs.create(filename)
fs.ensure(path)
fs.move(src,dest)
fs.copy(src,dest)
fs.remove(src)
fs.remove(src,true)
fs.removeDir(path)
Upload and download
var promise = fs.upload(source,destination,[options],[onprogress]);
var promise = fs.upload(source,destination,[onprogress]);
var promise = fs.download(source,destination,[options],[onprogress]);
var promise = fs.download(source,destination,[onprogress]);
promise.progress(function(progressEvent){...})
promise.abort();
fs.upload(...).then(...)
Utilities
fs.fs
fs.filename(path)
fs.dirname(path)
Changelog
0.3.0 (05/11/2014)
- Added
list
options (list r
ecursively, only f
iles, only d
irectories, return result as e
ntries)
0.2.0 (05/11/2014)
- Added
upload
and download
methods with concurrency limit
Contribute
Feel free to contribute to this project in any way. The easiest way to support this project is by giving it a star.
Contact
© 2014 - Mark Marijnissen