cordova-file-cache
Advanced tools
Comparing version 0.2.1 to 0.2.2
{ | ||
"name": "cordova-file-cache", | ||
"main": "dist/CordovaFileCache.js", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"homepage": "https://github.com/markmarijnissen/cordova-file-cache", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -172,35 +172,44 @@ var CordovaFileCache = | ||
// augment progress event with index/total stats | ||
var onSingleDownloadProgress; | ||
if(typeof onprogress === 'function') { | ||
onSingleDownloadProgress = function(ev){ | ||
ev.index = index; | ||
ev.total = total; | ||
onprogress(ev); | ||
}; | ||
} | ||
// callback | ||
var onDone = function(){ | ||
index++; | ||
// when we're done | ||
if(index !== total) { | ||
// reset downloads | ||
self._downloading = []; | ||
// check if we got everything | ||
self.list().then(function(){ | ||
// Yes, we're not dirty anymore! | ||
if(!self.isDirty()) { | ||
resolve(self); | ||
// Aye, some files got left behind! | ||
} else { | ||
reject(self.getDownloadQueue()); | ||
// download every file in the queue (which is the diff from _added with _cached) | ||
queue.forEach(function(url){ | ||
var path = self.toPath(url); | ||
// augment progress event with index/total stats | ||
var onSingleDownloadProgress; | ||
if(typeof onprogress === 'function') { | ||
onSingleDownloadProgress = function(ev){ | ||
ev.queueIndex = index; | ||
ev.queueSize = total; | ||
ev.url = url; | ||
ev.path = path; | ||
ev.percentage = index / total; | ||
if(ev.loaded > 0 && ev.total > 0 && index !== total){ | ||
ev.percentage += (ev.loaded / ev.total) / total; | ||
} | ||
},reject); | ||
onprogress(ev); | ||
}; | ||
} | ||
}; | ||
// download every file in the queue (which is the diff from _added with _cached) | ||
queue.forEach(function(url,index){ | ||
var download = fs.download(url,self.toPath(url),{retry:self._retry},onSingleDownloadProgress); | ||
// callback | ||
var onDone = function(){ | ||
index++; | ||
// when we're done | ||
if(index === total) { | ||
// reset downloads | ||
self._downloading = []; | ||
// check if we got everything | ||
self.list().then(function(){ | ||
// final progress event! | ||
if(onSingleDownloadProgress) onSingleDownloadProgress(new ProgressEvent()); | ||
// Yes, we're not dirty anymore! | ||
if(!self.isDirty()) { | ||
resolve(self); | ||
// Aye, some files got left behind! | ||
} else { | ||
reject(self.getDownloadQueue()); | ||
} | ||
},reject); | ||
} | ||
}; | ||
var download = fs.download(url,path,{retry:self._retry},onSingleDownloadProgress); | ||
download.then(onDone,onDone); | ||
@@ -207,0 +216,0 @@ self._downloading.push(download); |
69
index.js
@@ -125,35 +125,44 @@ var hash = require('./murmerhash'); | ||
// augment progress event with index/total stats | ||
var onSingleDownloadProgress; | ||
if(typeof onprogress === 'function') { | ||
onSingleDownloadProgress = function(ev){ | ||
ev.index = index; | ||
ev.total = total; | ||
onprogress(ev); | ||
}; | ||
} | ||
// callback | ||
var onDone = function(){ | ||
index++; | ||
// when we're done | ||
if(index !== total) { | ||
// reset downloads | ||
self._downloading = []; | ||
// check if we got everything | ||
self.list().then(function(){ | ||
// Yes, we're not dirty anymore! | ||
if(!self.isDirty()) { | ||
resolve(self); | ||
// Aye, some files got left behind! | ||
} else { | ||
reject(self.getDownloadQueue()); | ||
// download every file in the queue (which is the diff from _added with _cached) | ||
queue.forEach(function(url){ | ||
var path = self.toPath(url); | ||
// augment progress event with index/total stats | ||
var onSingleDownloadProgress; | ||
if(typeof onprogress === 'function') { | ||
onSingleDownloadProgress = function(ev){ | ||
ev.queueIndex = index; | ||
ev.queueSize = total; | ||
ev.url = url; | ||
ev.path = path; | ||
ev.percentage = index / total; | ||
if(ev.loaded > 0 && ev.total > 0 && index !== total){ | ||
ev.percentage += (ev.loaded / ev.total) / total; | ||
} | ||
},reject); | ||
onprogress(ev); | ||
}; | ||
} | ||
}; | ||
// download every file in the queue (which is the diff from _added with _cached) | ||
queue.forEach(function(url,index){ | ||
var download = fs.download(url,self.toPath(url),{retry:self._retry},onSingleDownloadProgress); | ||
// callback | ||
var onDone = function(){ | ||
index++; | ||
// when we're done | ||
if(index === total) { | ||
// reset downloads | ||
self._downloading = []; | ||
// check if we got everything | ||
self.list().then(function(){ | ||
// final progress event! | ||
if(onSingleDownloadProgress) onSingleDownloadProgress(new ProgressEvent()); | ||
// Yes, we're not dirty anymore! | ||
if(!self.isDirty()) { | ||
resolve(self); | ||
// Aye, some files got left behind! | ||
} else { | ||
reject(self.getDownloadQueue()); | ||
} | ||
},reject); | ||
} | ||
}; | ||
var download = fs.download(url,path,{retry:self._retry},onSingleDownloadProgress); | ||
download.then(onDone,onDone); | ||
@@ -160,0 +169,0 @@ self._downloading.push(download); |
{ | ||
"name": "cordova-file-cache", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Cordova File Cache", | ||
@@ -22,4 +22,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"cordova-promise-fs": "^0.5.0" | ||
"cordova-promise-fs": "^0.5.1" | ||
} | ||
} |
@@ -5,2 +5,3 @@ cordova-file-cache | ||
Based on [cordova-promise-fs](https://github.com/markmarijnissen/cordova-promise-fs). | ||
@@ -7,0 +8,0 @@ ## Getting started |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25452
589
140
Updatedcordova-promise-fs@^0.5.1