Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cordova-promise-fs

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cordova-promise-fs - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

115

dist/CordovaPromiseFS.js

@@ -122,2 +122,3 @@ var CordovaPromiseFS =

options.retry = options.retry || [];
options.debug = !!options.debug;

@@ -143,3 +144,3 @@ /* Cordova deviceready promise */

if (xhr.readyState == 4) {
if(xhr.status === 200){
if(xhr.status === 200 && !this._aborted){
write(file,xhr.response).then(win,fail);

@@ -154,2 +155,5 @@ } else {

};
FileTransfer.prototype.abort = function(){
this._aborted = true;
};
window.ProgressEvent = function ProgressEvent(){};

@@ -182,12 +186,13 @@ window.FileEntry = function FileEntry(){};

window.requestFileSystem(type, grantedBytes, resolve, reject);
});
}
// Exotic Cordova Directories (options.fileSystem = string)
if(isNaN(type)) {
window.resolveLocalFileSystemURL(type,function(directory){
resolve(directory.filesystem);
},reject);
// Normal browser usage
}, reject);
} else {
window.requestFileSystem(type, options.storageSize, resolve, reject);
// Exotic Cordova Directories (options.fileSystem = string)
if(isNaN(type)) {
window.resolveLocalFileSystemURL(type,function(directory){
resolve(directory.filesystem);
},reject);
// Normal browser usage
} else {
window.requestFileSystem(type, options.storageSize, resolve, reject);
}
}

@@ -201,2 +206,4 @@

fs.then(function(fs){
CDV_INTERNAL_URL_ROOT = fs.root.toInternalURL();
CDV_URL_ROOT = fs.root.toURL();
window.__fs = fs;

@@ -267,33 +274,20 @@ },function(err){

var dirReader = dirEntry.createReader();
var totalEntities=[];
var readDir = function(entries) {
if(entries.length===0) {
return ResolvedPromise(totalEntities).then(function(){resolve(totalEntities);});
} else {
var promises = [ResolvedPromise(entries)];
if(recursive) {
entries
.filter(function(entry){return entry.isDirectory; })
.forEach(function(entry){
promises.push(list(entry.fullPath,'re'));
});
}
promises.push(new Promise(function(re,rej){
dirReader.readEntries(function(eents) {
readDir(eents).then(function(){re(eents);},rej);
}, reject);
}));
if(onlyFiles) entries = entries.filter(function(entry) { return entry.isFile; });
if(onlyDirs) entries = entries.filter(function(entry) { return entry.isDirectory; });
if(!getAsEntries) entries = entries.map(function(entry) { return entry.fullPath; });
totalEntities = totalEntities.concat.apply(totalEntities,entries);
return Promise.all(promises);
dirReader.readEntries(function(entries) {
var promises = [ResolvedPromise(entries)];
if(recursive) {
entries
.filter(function(entry){return entry.isDirectory; })
.forEach(function(entry){
promises.push(list(entry.fullPath,'re'));
});
}
};
dirReader.readEntries(readDir, reject);
Promise.all(promises).then(function(values){
var entries = [];
entries = entries.concat.apply(entries,values);
if(onlyFiles) entries = entries.filter(function(entry) { return entry.isFile; });
if(onlyDirs) entries = entries.filter(function(entry) { return entry.isDirectory; });
if(!getAsEntries) entries = entries.map(function(entry) { return entry.fullPath; });
resolve(entries);
},reject);
}, reject);
},reject);

@@ -353,3 +347,5 @@ });

/* convert path to URL to be used in JS/CSS/HTML */
var toInternalURL,toInternalURLSync;
var toInternalURL,toInternalURLSync,toURLSync;
CDV_INTERNAL_URL_ROOT = 'cdvfile://localhost/'+(options.persistent? 'persistent/':'temporary/');
CDV_URL_ROOT = '';
if(isCordova) {

@@ -359,4 +355,9 @@ /* synchronous helper to get internal URL. */

path = normalize(path);
return path.indexOf('://') < 0? 'cdvfile://localhost/'+(options.persistent? 'persistent/':'temporary/') + path: path;
return path.indexOf('://') < 0? CDV_INTERNAL_URL_ROOT + path: path;
};
/* synchronous helper to get native URL. */
toURLSync = function(path){
path = normalize(path);
return path.indexOf('://') < 0? CDV_URL_ROOT + path: path;
};

@@ -380,2 +381,3 @@ toInternalURL = function(path) {

};
toURLSync = toInternalURLSync;
}

@@ -419,5 +421,5 @@

if(typeof blob === 'string') {
blob = new Blob([blob],{type: mimeType || 'text/plain'});
blob = createBlob([blob], mimeType || 'text/plain');
} else if(blob instanceof Blob !== true){
blob = new Blob([JSON.stringify(blob,null,4)],{type: mimeType || 'application/json'});
blob = createBlob([JSON.stringify(blob,null,4)], mimeType || 'application/json');
}

@@ -430,2 +432,22 @@ writer.write(blob);

function createBlob(parts, type) {
var BlobBuilder,
bb;
try {
return new Blob(parts, {type: type});
} catch(e) {
BlobBuilder = window.BlobBuilder ||
window.WebKitBlobBuilder ||
window.MozBlobBuilder ||
window.MSBlobBuilder;
if(BlobBuilder) {
bb = new BlobBuilder();
bb.append(parts);
return bb.getBlob(type);
} else {
throw new Error("Unable to create blob");
}
}
}
/* move a file */

@@ -537,3 +559,3 @@ function move(src,dest) {

}
if(isCordova && localPath.indexOf('://') < 0) localPath = toInternalURLSync(localPath);
if(isCordova && localPath.indexOf('://') < 0) localPath = toURLSync(localPath);

@@ -555,2 +577,3 @@ transferOptions = transferOptions || {};

if(transferOptions.retry.length === 0) {
if(options.debug) console.log('FileTransfer Error: '+serverUrl,err);
reject(err);

@@ -567,3 +590,3 @@ } else {

win:resolve,
fail:attempt
fail:attempt
};

@@ -570,0 +593,0 @@ transferQueue.unshift(transferJob);

@@ -75,2 +75,3 @@ /**

options.retry = options.retry || [];
options.debug = !!options.debug;

@@ -96,3 +97,3 @@ /* Cordova deviceready promise */

if (xhr.readyState == 4) {
if(xhr.status === 200){
if(xhr.status === 200 && !this._aborted){
write(file,xhr.response).then(win,fail);

@@ -107,2 +108,5 @@ } else {

};
FileTransfer.prototype.abort = function(){
this._aborted = true;
};
window.ProgressEvent = function ProgressEvent(){};

@@ -135,12 +139,13 @@ window.FileEntry = function FileEntry(){};

window.requestFileSystem(type, grantedBytes, resolve, reject);
});
}
// Exotic Cordova Directories (options.fileSystem = string)
if(isNaN(type)) {
window.resolveLocalFileSystemURL(type,function(directory){
resolve(directory.filesystem);
},reject);
// Normal browser usage
}, reject);
} else {
window.requestFileSystem(type, options.storageSize, resolve, reject);
// Exotic Cordova Directories (options.fileSystem = string)
if(isNaN(type)) {
window.resolveLocalFileSystemURL(type,function(directory){
resolve(directory.filesystem);
},reject);
// Normal browser usage
} else {
window.requestFileSystem(type, options.storageSize, resolve, reject);
}
}

@@ -154,2 +159,4 @@

fs.then(function(fs){
CDV_INTERNAL_URL_ROOT = fs.root.toInternalURL();
CDV_URL_ROOT = fs.root.toURL();
window.__fs = fs;

@@ -220,33 +227,20 @@ },function(err){

var dirReader = dirEntry.createReader();
var totalEntities=[];
var readDir = function(entries) {
if(entries.length===0) {
return ResolvedPromise(totalEntities).then(function(){resolve(totalEntities);});
} else {
var promises = [ResolvedPromise(entries)];
if(recursive) {
entries
.filter(function(entry){return entry.isDirectory; })
.forEach(function(entry){
promises.push(list(entry.fullPath,'re'));
});
}
promises.push(new Promise(function(re,rej){
dirReader.readEntries(function(eents) {
readDir(eents).then(function(){re(eents);},rej);
}, reject);
}));
if(onlyFiles) entries = entries.filter(function(entry) { return entry.isFile; });
if(onlyDirs) entries = entries.filter(function(entry) { return entry.isDirectory; });
if(!getAsEntries) entries = entries.map(function(entry) { return entry.fullPath; });
totalEntities = totalEntities.concat.apply(totalEntities,entries);
return Promise.all(promises);
dirReader.readEntries(function(entries) {
var promises = [ResolvedPromise(entries)];
if(recursive) {
entries
.filter(function(entry){return entry.isDirectory; })
.forEach(function(entry){
promises.push(list(entry.fullPath,'re'));
});
}
};
dirReader.readEntries(readDir, reject);
Promise.all(promises).then(function(values){
var entries = [];
entries = entries.concat.apply(entries,values);
if(onlyFiles) entries = entries.filter(function(entry) { return entry.isFile; });
if(onlyDirs) entries = entries.filter(function(entry) { return entry.isDirectory; });
if(!getAsEntries) entries = entries.map(function(entry) { return entry.fullPath; });
resolve(entries);
},reject);
}, reject);
},reject);

@@ -306,3 +300,5 @@ });

/* convert path to URL to be used in JS/CSS/HTML */
var toInternalURL,toInternalURLSync;
var toInternalURL,toInternalURLSync,toURLSync;
CDV_INTERNAL_URL_ROOT = 'cdvfile://localhost/'+(options.persistent? 'persistent/':'temporary/');
CDV_URL_ROOT = '';
if(isCordova) {

@@ -312,4 +308,9 @@ /* synchronous helper to get internal URL. */

path = normalize(path);
return path.indexOf('://') < 0? 'cdvfile://localhost/'+(options.persistent? 'persistent/':'temporary/') + path: path;
return path.indexOf('://') < 0? CDV_INTERNAL_URL_ROOT + path: path;
};
/* synchronous helper to get native URL. */
toURLSync = function(path){
path = normalize(path);
return path.indexOf('://') < 0? CDV_URL_ROOT + path: path;
};

@@ -333,2 +334,3 @@ toInternalURL = function(path) {

};
toURLSync = toInternalURLSync;
}

@@ -372,5 +374,5 @@

if(typeof blob === 'string') {
blob = new Blob([blob],{type: mimeType || 'text/plain'});
blob = createBlob([blob], mimeType || 'text/plain');
} else if(blob instanceof Blob !== true){
blob = new Blob([JSON.stringify(blob,null,4)],{type: mimeType || 'application/json'});
blob = createBlob([JSON.stringify(blob,null,4)], mimeType || 'application/json');
}

@@ -383,2 +385,22 @@ writer.write(blob);

function createBlob(parts, type) {
var BlobBuilder,
bb;
try {
return new Blob(parts, {type: type});
} catch(e) {
BlobBuilder = window.BlobBuilder ||
window.WebKitBlobBuilder ||
window.MozBlobBuilder ||
window.MSBlobBuilder;
if(BlobBuilder) {
bb = new BlobBuilder();
bb.append(parts);
return bb.getBlob(type);
} else {
throw new Error("Unable to create blob");
}
}
}
/* move a file */

@@ -490,3 +512,3 @@ function move(src,dest) {

}
if(isCordova && localPath.indexOf('://') < 0) localPath = toInternalURLSync(localPath);
if(isCordova && localPath.indexOf('://') < 0) localPath = toURLSync(localPath);

@@ -508,2 +530,3 @@ transferOptions = transferOptions || {};

if(transferOptions.retry.length === 0) {
if(options.debug) console.log('FileTransfer Error: '+serverUrl,err);
reject(err);

@@ -520,3 +543,3 @@ } else {

win:resolve,
fail:attempt
fail:attempt
};

@@ -523,0 +546,0 @@ transferQueue.unshift(transferJob);

2

package.json
{
"name": "cordova-promise-fs",
"version": "1.0.1",
"version": "1.1.0",
"description": "Cordova FileSystem convienence functions that return promises.",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc