cordova-promise-fs
Advanced tools
Comparing version 0.5.1 to 0.6.0
{ | ||
"name": "cordova-promise-fs", | ||
"main": "dist/CordovaPromiseFS.js", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"homepage": "https://github.com/markmarijnissen/cordova-promise-fs", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -98,6 +98,35 @@ var CordovaPromiseFS = | ||
/* Cordova deviceready promise */ | ||
var deviceready = new Promise(function(resolve,reject){ | ||
document.addEventListener("deviceready", resolve, false); | ||
setTimeout(function(){ reject(new Error('deviceready has not fired after 5 seconds.')); },5100); | ||
}); | ||
var deviceready, isCordova = typeof cordova !== 'undefined'; | ||
if(isCordova){ | ||
deviceready = new Promise(function(resolve,reject){ | ||
document.addEventListener("deviceready", resolve, false); | ||
setTimeout(function(){ reject(new Error('deviceready has not fired after 5 seconds.')); },5100); | ||
}); | ||
} else { | ||
/* FileTransfer implementation for Chrome */ | ||
deviceready = Promise.resolve(); | ||
if(typeof webkitRequestFileSystem !== 'undefined'){ | ||
window.requestFileSystem = webkitRequestFileSystem; | ||
window.FileTransfer = function FileTransfer(){}; | ||
FileTransfer.prototype.download = function download(url,file,win,fail) { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', url); | ||
xhr.onreadystatechange = function(onSuccess, onError, cb) { | ||
if (xhr.readyState == 4) { | ||
if(xhr.status === 200){ | ||
write(file,xhr.responseText).then(win,fail); | ||
} else { | ||
fail(xhr.status); | ||
} | ||
} | ||
}; | ||
xhr.send(); | ||
return xhr; | ||
}; | ||
} else { | ||
window.requestFileSystem = function(x,y,z,fail){ | ||
fail(new Error('requestFileSystem not supported!')); | ||
}; | ||
} | ||
} | ||
@@ -168,14 +197,28 @@ | ||
/* convert path to URL to be used in JS/CSS/HTML */ | ||
function toInternalURL(path) { | ||
return file(path).then(function(fileEntry) { | ||
return fileEntry.toInternalURL(); | ||
}); | ||
} | ||
if(isCordova) { | ||
/* synchronous helper to get internal URL. */ | ||
function toInternalURLSync(path){ | ||
if(path[0] !== '/') path = '/' + path; | ||
return 'cdvfile://localhost/'+(options.persistent? 'persistent':'temporary') + path; | ||
} | ||
/* synchronous helper to get internal URL. */ | ||
function toInternalURLSync(path){ | ||
if(path[0] !== '/') path = '/' + path; | ||
return 'cdvfile://localhost/'+(options.persistent? 'persistent':'temporary') + path; | ||
} | ||
function toInternalURL(path) { | ||
return file(path).then(function(fileEntry) { | ||
return fileEntry.toInternalURL(); | ||
}); | ||
} | ||
} else { | ||
/* synchronous helper to get internal URL. */ | ||
function toInternalURLSync(path){ | ||
if(path[0] !== '/') path = '/' + path; | ||
return 'filesystem:'+location.origin+(options.persistent? '/persistent':'/temporary') + path; | ||
} | ||
function toInternalURL(path) { | ||
return file(path).then(function(fileEntry) { | ||
return fileEntry.toURL(); | ||
}); | ||
} | ||
} | ||
/* convert path to base64 date URI */ | ||
@@ -345,2 +388,8 @@ function toDataURL(path) { | ||
var isDownload = args.shift(); | ||
var serverUrl = args.shift(); | ||
var localPath = args.shift(); | ||
var win = args.shift(); | ||
var fail = args.shift(); | ||
var trustAllHosts = args.shift(); | ||
var transferOptions = args.shift(); | ||
@@ -350,10 +399,6 @@ if(ft._aborted) { | ||
} else if(isDownload){ | ||
ft.download.apply(ft,args); | ||
ft.download.call(ft,serverUrl,localPath,win,fail,transferOptions,trustAllHosts); | ||
if(ft.onprogress) ft.onprogress(new ProgressEvent()); | ||
} else { | ||
// Stupid API. 'upload' switched around the 'trustAllHosts' and 'options' arguments. | ||
var opts = args[4]; args[4] = args[5]; args[5] = opts; | ||
// Switch around serverUrl/localPath because we transfer in reverse direction | ||
var localPath = args[1]; args[1] = args[0]; args[0] = localPath; | ||
ft.upload.apply(ft,args); | ||
ft.upload.call(ft,localPath,serverUrl,win,fail,trustAllHosts,transferOptions); | ||
} | ||
@@ -378,3 +423,3 @@ } | ||
serverUrl = encodeURI(serverUrl); | ||
localPath = toInternalURLSync(localPath); | ||
if(isCordova) localPath = toInternalURLSync(localPath); | ||
@@ -448,2 +493,4 @@ transferOptions = transferOptions || {}; | ||
toURL:toURL, | ||
isCordova:isCordova, | ||
toInternalURLSync: toInternalURLSync, | ||
toInternalURL:toInternalURL, | ||
@@ -450,0 +497,0 @@ toDataURL:toDataURL, |
89
index.js
@@ -51,6 +51,35 @@ /** | ||
/* Cordova deviceready promise */ | ||
var deviceready = new Promise(function(resolve,reject){ | ||
document.addEventListener("deviceready", resolve, false); | ||
setTimeout(function(){ reject(new Error('deviceready has not fired after 5 seconds.')); },5100); | ||
}); | ||
var deviceready, isCordova = typeof cordova !== 'undefined'; | ||
if(isCordova){ | ||
deviceready = new Promise(function(resolve,reject){ | ||
document.addEventListener("deviceready", resolve, false); | ||
setTimeout(function(){ reject(new Error('deviceready has not fired after 5 seconds.')); },5100); | ||
}); | ||
} else { | ||
/* FileTransfer implementation for Chrome */ | ||
deviceready = Promise.resolve(); | ||
if(typeof webkitRequestFileSystem !== 'undefined'){ | ||
window.requestFileSystem = webkitRequestFileSystem; | ||
window.FileTransfer = function FileTransfer(){}; | ||
FileTransfer.prototype.download = function download(url,file,win,fail) { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', url); | ||
xhr.onreadystatechange = function(onSuccess, onError, cb) { | ||
if (xhr.readyState == 4) { | ||
if(xhr.status === 200){ | ||
write(file,xhr.responseText).then(win,fail); | ||
} else { | ||
fail(xhr.status); | ||
} | ||
} | ||
}; | ||
xhr.send(); | ||
return xhr; | ||
}; | ||
} else { | ||
window.requestFileSystem = function(x,y,z,fail){ | ||
fail(new Error('requestFileSystem not supported!')); | ||
}; | ||
} | ||
} | ||
@@ -121,14 +150,28 @@ | ||
/* convert path to URL to be used in JS/CSS/HTML */ | ||
function toInternalURL(path) { | ||
return file(path).then(function(fileEntry) { | ||
return fileEntry.toInternalURL(); | ||
}); | ||
} | ||
if(isCordova) { | ||
/* synchronous helper to get internal URL. */ | ||
function toInternalURLSync(path){ | ||
if(path[0] !== '/') path = '/' + path; | ||
return 'cdvfile://localhost/'+(options.persistent? 'persistent':'temporary') + path; | ||
} | ||
/* synchronous helper to get internal URL. */ | ||
function toInternalURLSync(path){ | ||
if(path[0] !== '/') path = '/' + path; | ||
return 'cdvfile://localhost/'+(options.persistent? 'persistent':'temporary') + path; | ||
} | ||
function toInternalURL(path) { | ||
return file(path).then(function(fileEntry) { | ||
return fileEntry.toInternalURL(); | ||
}); | ||
} | ||
} else { | ||
/* synchronous helper to get internal URL. */ | ||
function toInternalURLSync(path){ | ||
if(path[0] !== '/') path = '/' + path; | ||
return 'filesystem:'+location.origin+(options.persistent? '/persistent':'/temporary') + path; | ||
} | ||
function toInternalURL(path) { | ||
return file(path).then(function(fileEntry) { | ||
return fileEntry.toURL(); | ||
}); | ||
} | ||
} | ||
/* convert path to base64 date URI */ | ||
@@ -298,2 +341,8 @@ function toDataURL(path) { | ||
var isDownload = args.shift(); | ||
var serverUrl = args.shift(); | ||
var localPath = args.shift(); | ||
var win = args.shift(); | ||
var fail = args.shift(); | ||
var trustAllHosts = args.shift(); | ||
var transferOptions = args.shift(); | ||
@@ -303,10 +352,6 @@ if(ft._aborted) { | ||
} else if(isDownload){ | ||
ft.download.apply(ft,args); | ||
ft.download.call(ft,serverUrl,localPath,win,fail,transferOptions,trustAllHosts); | ||
if(ft.onprogress) ft.onprogress(new ProgressEvent()); | ||
} else { | ||
// Stupid API. 'upload' switched around the 'trustAllHosts' and 'options' arguments. | ||
var opts = args[4]; args[4] = args[5]; args[5] = opts; | ||
// Switch around serverUrl/localPath because we transfer in reverse direction | ||
var localPath = args[1]; args[1] = args[0]; args[0] = localPath; | ||
ft.upload.apply(ft,args); | ||
ft.upload.call(ft,localPath,serverUrl,win,fail,trustAllHosts,transferOptions); | ||
} | ||
@@ -331,3 +376,3 @@ } | ||
serverUrl = encodeURI(serverUrl); | ||
localPath = toInternalURLSync(localPath); | ||
if(isCordova) localPath = toInternalURLSync(localPath); | ||
@@ -401,2 +446,4 @@ transferOptions = transferOptions || {}; | ||
toURL:toURL, | ||
isCordova:isCordova, | ||
toInternalURLSync: toInternalURLSync, | ||
toInternalURL:toInternalURL, | ||
@@ -403,0 +450,0 @@ toDataURL:toDataURL, |
{ | ||
"name": "cordova-promise-fs", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Cordova FileSystem convienence functions that return promises.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
cordova-promise-fs | ||
========== | ||
> Wraps the Cordova File API in convenient functions (that return a Promise) | ||
> Wraps the Cordova (and Chrome) File API in convenient functions (that return a Promise) | ||
@@ -107,2 +107,3 @@ Are you entangled in a async callback mess to get even the simplest task done? Wait no longer -- here is **cordova-promise-fs**! | ||
fs.options // options | ||
fs.isCordova // is Cordova App? | ||
``` | ||
@@ -112,2 +113,6 @@ | ||
### 0.6.0 (13/11/2014) | ||
* Chrome Support! | ||
### 0.5.0 (06/11/2014) | ||
@@ -114,0 +119,0 @@ |
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
35123
889
149