diff --git a/README.md b/README.md index df5f985..2ceeed3 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ fs.dirname(path) // converts path dirname (everything except part after last /) fs.deviceready // deviceready promise fs.options // options fs.isCordova // is Cordova App? +fs.availableSpace() // returns promise with available space in bytes ``` ### Normalized path diff --git a/dist/CordovaPromiseFS.js b/dist/CordovaPromiseFS.js index d9aeb3a..ca998da 100644 --- a/dist/CordovaPromiseFS.js +++ b/dist/CordovaPromiseFS.js @@ -610,6 +610,20 @@ var CordovaPromiseFS = return filetransfer(false,dest,source,options,onprogress); } + function availableSpace(){ + return new Promise(function(resolve,reject) { + if(!isCordova) { + resolve(100) + } else { + cordova.exec(function(result) { + resolve(result); + }, function(error) { + reject(error); + }, "File", "getFreeDiskSpace", []); + } + }); + } + return { fs: fs, normalize: normalize, @@ -637,6 +651,7 @@ var CordovaPromiseFS = toInternalURLSync: toInternalURLSync, toInternalURL:toInternalURL, toDataURL:toDataURL, + availableSpace: availableSpace, deviceready: deviceready, options: options, Promise: Promise diff --git a/index.js b/index.js index 73e8f79..d2a3a60 100644 --- a/index.js +++ b/index.js @@ -563,6 +563,20 @@ module.exports = function(options){ return filetransfer(false,dest,source,options,onprogress); } + function availableSpace(){ + return new Promise(function(resolve,reject) { + if(!isCordova) { + resolve(100) + } else { + cordova.exec(function(result) { + resolve(result); + }, function(error) { + reject(error); + }, "File", "getFreeDiskSpace", []); + } + }); + } + return { fs: fs, normalize: normalize, @@ -590,6 +604,7 @@ module.exports = function(options){ toInternalURLSync: toInternalURLSync, toInternalURL:toInternalURL, toDataURL:toDataURL, + availableSpace: availableSpace, deviceready: deviceready, options: options, Promise: Promise diff --git a/package.json b/package.json index 119e342..3398a1d 100644 --- a/package.json +++ b/package.json @@ -19,5 +19,8 @@ "promise" ], "author": "Mark Marijnissen", - "license": "MIT" + "license": "MIT", + "devDependencies": { + "webpack": "^1.13.1" + } }