From 30d6077586aef606acc7b4664406bcff61f9dcf2 Mon Sep 17 00:00:00 2001 From: Gerhard Sletten Date: Mon, 30 May 2016 15:34:47 +0200 Subject: [PATCH] Added webpack to devDependencies and utility function to check for available space on device --- README.md | 1 + dist/CordovaPromiseFS.js | 15 +++++++++++++++ index.js | 15 +++++++++++++++ package.json | 5 ++++- 4 files changed, 35 insertions(+), 1 deletion(-) 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" + } }