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

cordova-plugin-file

Package Overview
Dependencies
Maintainers
3
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cordova-plugin-file - npm Package Compare versions

Comparing version 4.1.1 to 4.2.0

.jshintrc

11

package.json
{
"name": "cordova-plugin-file",
"version": "4.1.1",
"version": "4.2.0",
"description": "Cordova File Plugin",

@@ -41,4 +41,11 @@ "cordova": {

],
"scripts": {
"test": "npm run jshint",
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests"
},
"author": "Apache Software Foundation",
"license": "Apache-2.0"
"license": "Apache-2.0",
"devDependencies": {
"jshint": "^2.6.0"
}
}

4

README.md

@@ -20,2 +20,4 @@ <!--

[![Build Status](https://travis-ci.org/apache/cordova-plugin-file.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-file)
# cordova-plugin-file

@@ -52,3 +54,3 @@

:warning: Report issues on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20File%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC)
Report issues on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20File%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC)

@@ -55,0 +57,0 @@ ## Installation

@@ -23,2 +23,16 @@ <!--

### 4.2.0 (Apr 15, 2016)
* CB-10960 Uncaught `#<FileError>` in `write()` when `readyState != WRITING ?`
* Replace `PermissionHelper.java` with `cordova-plugin-compat`
* CB-10977 **Android** Removing global state used for permission requests
* CB-10798, CB-10384 Fixing permissions for **Marshmallow**.
* Fix test failure on **WP 8.1**
* CB-10577 **Windows** `resolveLocalFileSystemURL` should omit trailing slash for file
* CB-7862 `FileReader` reads large files in chunks with progress.
* CB-10577 **Android** `resolveLocalFileSystemURL` should detect directory vs file.
* CB-9753 index out of bounds on `requestFileSystem`.
* Remove `warning` emoji, as it doesn't correctly display in the docs website: cordova.apache.org/docs/en/dev/cordova-plugin-file/index.html. This closes #166
* CB-10636 Add `JSHint` for plugins
* CB-10411 Error in `file.spec.129` of `cordova-plugin-file`
### 4.1.1 (Feb 09, 2016)

@@ -25,0 +39,0 @@ * Edit package.json license to match SPDX id

@@ -21,2 +21,5 @@ /*

*/
/* global PluginResult */
module.exports = {

@@ -23,0 +26,0 @@ setSandbox : function (success, fail, args, env) {

@@ -91,3 +91,5 @@ /*

if (type !== LocalFileSystem.TEMPORARY && type !== LocalFileSystem.PERSISTENT) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -240,3 +242,5 @@ }

if (!data) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -525,3 +529,5 @@ }

if (path.trim()[0] === '/') {
errorCallback && errorCallback(FileError.ENCODING_ERR);
if (errorCallback) {
errorCallback(FileError.ENCODING_ERR);
}
return;

@@ -533,3 +539,5 @@ }

if (path.indexOf("cdvfile://localhost") === -1) {
errorCallback && errorCallback(FileError.ENCODING_ERR);
if (errorCallback) {
errorCallback(FileError.ENCODING_ERR);
}
return;

@@ -547,3 +555,5 @@ }

} else {
errorCallback && errorCallback(FileError.ENCODING_ERR);
if (errorCallback) {
errorCallback(FileError.ENCODING_ERR);
}
return;

@@ -608,3 +618,5 @@ }

xhr.onerror = function () {
errorCallback && errorCallback(FileError.NOT_READABLE_ERR);
if(errorCallback) {
errorCallback(FileError.NOT_READABLE_ERR);
}
};

@@ -614,3 +626,5 @@

} else {
errorCallback && errorCallback(FileError.NOT_FOUND_ERR);
if(errorCallback) {
errorCallback(FileError.NOT_FOUND_ERR);
}
}

@@ -627,3 +641,5 @@

fileWriter.onerror = function () {
errorCallback && errorCallback(FileError.NOT_READABLE_ERR);
if (errorCallback) {
errorCallback(FileError.NOT_READABLE_ERR);
}
};

@@ -830,3 +846,5 @@ fileWriter.write(new Blob([xhr.response]));

if (!this.db) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -847,3 +865,5 @@ }

if (!this.db) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -909,3 +929,5 @@ }

if (!idb_.db) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -940,3 +962,5 @@ }

if (!this.db) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -943,0 +967,0 @@ }

@@ -22,2 +22,4 @@ /*

/* global IDBKeyRange */
var LocalFileSystem = require('./LocalFileSystem'),

@@ -71,6 +73,8 @@ FileSystem = require('./FileSystem'),

var type = args[0];
var size = args[1];
//var size = args[1];
if (type !== LocalFileSystem.TEMPORARY && type !== LocalFileSystem.PERSISTENT) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -211,7 +215,9 @@ }

data = args[1],
position = args[2],
isBinary = args[3];
position = args[2];
//isBinary = args[3];
if (!data) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -399,4 +405,4 @@ }

var srcPath = args[0];
var parentFullPath = args[1];
var name = args[2];
//var parentFullPath = args[1];
//var name = args[2];

@@ -456,3 +462,5 @@ exports.copyTo(function (fileEntry) {

xhr.onerror = function () {
errorCallback && errorCallback(FileError.NOT_READABLE_ERR);
if (errorCallback) {
errorCallback(FileError.NOT_READABLE_ERR);
}
};

@@ -462,3 +470,5 @@

} else {
errorCallback && errorCallback(FileError.NOT_FOUND_ERR);
if (errorCallback) {
errorCallback(FileError.NOT_FOUND_ERR);
}
}

@@ -475,3 +485,5 @@

fileWriter.onerror = function () {
errorCallback && errorCallback(FileError.NOT_READABLE_ERR);
if (errorCallback) {
errorCallback(FileError.NOT_READABLE_ERR);
}
};

@@ -650,3 +662,3 @@ fileWriter.write(new Blob([xhr.response]));

if (!self.db.objectStoreNames.contains(FILE_STORE_)) {
var store = self.db.createObjectStore(FILE_STORE_/*,{keyPath: 'id', autoIncrement: true}*/);
self.db.createObjectStore(FILE_STORE_/*,{keyPath: 'id', autoIncrement: true}*/);
}

@@ -671,3 +683,5 @@ };

if (!this.db) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -691,3 +705,5 @@ }

if (!this.db) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -702,3 +718,3 @@ }

range = IDBKeyRange.bound(
var range = IDBKeyRange.bound(
storagePath + DIR_SEPARATOR, storagePath + DIR_OPEN_BOUND, false, true);

@@ -744,3 +760,5 @@

if (!this.db) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -761,3 +779,5 @@ }

if (!this.db) {
errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR);
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
return;

@@ -764,0 +784,0 @@ }

@@ -22,3 +22,4 @@ /*

var cordova = require('cordova');
/* global Windows, WinJS, MSApp */
var File = require('./File'),

@@ -185,4 +186,2 @@ FileError = require('./FileError'),

if (!AllFileSystems) {
var storageFolderPermanent = Windows.Storage.ApplicationData.current.localFolder.path,
storageFolderTemporary = Windows.Storage.ApplicationData.current.temporaryFolder.path;
AllFileSystems = {

@@ -357,3 +356,3 @@ 'persistent':

var copyfolders = function() {
if (!todo--) {
if (!(todo--)) {
complete();

@@ -363,6 +362,6 @@ return;

copyFolder(the.folders[todo],dst)
.done(function() {copyfolders(); }, failed);
.done(function() { copyfolders(); }, failed);
};
var copyfiles = function() {
if (!todo--) {
if (!(todo--)) {
todo = the.folders.length;

@@ -373,5 +372,5 @@ copyfolders();

the.files[todo].copyAsync(the.fld)
.done(function() {copyfiles(); }, failed);
.done(function() { copyfiles(); }, failed);
};
copyfiles();
copyfiles();
},

@@ -386,7 +385,6 @@ failed

return new WinJS.Promise(function (complete,failed) {
var pending = [];
WinJS.Promise.join({
fld:dst.createFolderAsync(name, Windows.Storage.CreationCollisionOption.openIfExists),
files:src.getFilesAsync(),
folders:src.getFoldersAsync()
fld: dst.createFolderAsync(name, Windows.Storage.CreationCollisionOption.openIfExists),
files: src.getFilesAsync(),
folders: src.getFoldersAsync()
}).done(

@@ -400,3 +398,3 @@ function(the) {

var movefolders = function() {
if (!todo--) {
if (!(todo--)) {
src.deleteAsync().done(complete,failed);

@@ -409,3 +407,3 @@ return;

var movefiles = function() {
if (!todo--) {
if (!(todo--)) {
todo = the.folders.length;

@@ -416,5 +414,5 @@ movefolders();

the.files[todo].moveAsync(the.fld)
.done(function() {movefiles(); }, failed);
.done(function() { movefiles(); }, failed);
};
movefiles();
movefiles();
},

@@ -461,6 +459,5 @@ failed

}
if ( (the.src.folder && the.tgt.file)
|| (the.src.file && the.tgt.folder)
|| (the.tgt.folder && (the.tgt.files.length || the.tgt.folders.length)))
{
if ((the.src.folder && the.tgt.file) ||
(the.src.file && the.tgt.folder) ||
(the.tgt.folder && (the.tgt.files.length || the.tgt.folders.length))) {
fail(FileError.INVALID_MODIFICATION_ERR);

@@ -1107,3 +1104,2 @@ return;

fileContent = fileContent.substr(0, size);
var fullPath = storageFile.path;
var name = storageFile.name;

@@ -1184,3 +1180,2 @@ storageFile.deleteAsync().then(function () {

var uri = args[0];
var inputURL;

@@ -1187,0 +1182,0 @@ var path = pathFromURL(uri);

@@ -43,87 +43,89 @@ /*

fileName = args[2],
copiedEntry,
onSuccess = function () {
resolve(
function (entry) {
if (typeof(success) === 'function') {
success(entry);
}
},
onFail,
[destination + copiedEntry.name]
);
},
onFail = function (error) {
if (typeof(fail) === 'function') {
if (error && error.code) {
//set error codes expected by mobile spec
if (uri === destination) {
fail(FileError.INVALID_MODIFICATION_ERR);
} else if (error.code === FileError.SECURITY_ERR) {
fail(FileError.INVALID_MODIFICATION_ERR);
} else {
fail(error.code);
}
copiedEntry;
function onSuccess() {
resolve(
function (entry) {
if (typeof(success) === 'function') {
success(entry);
}
},
onFail,
[destination + copiedEntry.name]
);
}
function onFail(error) {
if (typeof(fail) === 'function') {
if (error && error.code) {
//set error codes expected by mobile spec
if (uri === destination) {
fail(FileError.INVALID_MODIFICATION_ERR);
} else if (error.code === FileError.SECURITY_ERR) {
fail(FileError.INVALID_MODIFICATION_ERR);
} else {
fail(error);
fail(error.code);
}
} else {
fail(error);
}
},
writeFile = function (fileEntry, blob, entry) {
copiedEntry = fileEntry;
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function () {
if (move) {
entry.nativeEntry.remove(onSuccess, function () {
console.error("Move operation failed. Files may exist at both source and destination");
}
}
function writeFile(fileEntry, blob, entry) {
copiedEntry = fileEntry;
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function () {
if (move) {
entry.nativeEntry.remove(onSuccess, function () {
console.error("Move operation failed. Files may exist at both source and destination");
});
} else {
onSuccess();
}
};
fileWriter.onerror = onFail;
fileWriter.write(blob);
}, onFail);
}
function copyFile(entry) {
if (entry.nativeEntry.file) {
entry.nativeEntry.file(function (file) {
var reader = new FileReader()._realReader;
reader.onloadend = function (e) {
var contents = new Uint8Array(this.result),
blob = new Blob([contents]);
resolve(function (destEntry) {
requestAnimationFrame(function () {
destEntry.nativeEntry.getFile(fileName, {create: true}, function (fileEntry) {
writeFile(fileEntry, blob, entry);
}, onFail);
});
} else {
onSuccess();
}
}, onFail, [destination]);
};
fileWriter.onerror = onFail;
fileWriter.write(blob);
reader.onerror = onFail;
reader.readAsArrayBuffer(file);
}, onFail);
},
copyFile = function (entry) {
if (entry.nativeEntry.file) {
entry.nativeEntry.file(function (file) {
var reader = new FileReader()._realReader;
reader.onloadend = function (e) {
var contents = new Uint8Array(this.result),
blob = new Blob([contents]);
resolve(function (destEntry) {
requestAnimationFrame(function () {
destEntry.nativeEntry.getFile(fileName, {create: true}, function (fileEntry) {
writeFile(fileEntry, blob, entry);
}, onFail);
});
}, onFail, [destination]);
};
reader.onerror = onFail;
reader.readAsArrayBuffer(file);
} else {
onFail(FileError.INVALID_MODIFICATION_ERR);
}
}
function copyDirectory(entry) {
resolve(function (destEntry) {
if (entry.filesystemName !== destEntry.filesystemName) {
console.error("Copying directories between filesystems is not supported on BB10");
onFail(FileError.INVALID_MODIFICATION_ERR);
} else {
entry.nativeEntry.copyTo(destEntry.nativeEntry, fileName, function () {
resolve(function (copiedDir) {
copiedEntry = copiedDir;
if (move) {
entry.nativeEntry.removeRecursively(onSuccess, onFail);
} else {
onSuccess();
}
}, onFail, [destination + fileName]);
}, onFail);
} else {
onFail(FileError.INVALID_MODIFICATION_ERR);
}
},
copyDirectory = function (entry) {
resolve(function (destEntry) {
if (entry.filesystemName !== destEntry.filesystemName) {
console.error("Copying directories between filesystems is not supported on BB10");
onFail(FileError.INVALID_MODIFICATION_ERR);
} else {
entry.nativeEntry.copyTo(destEntry.nativeEntry, fileName, function () {
resolve(function (copiedDir) {
copiedEntry = copiedDir;
if (move) {
entry.nativeEntry.removeRecursively(onSuccess, onFail);
} else {
onSuccess();
}
}, onFail, [destination + fileName]);
}, onFail);
}
}, onFail, [destination]);
};
}, onFail, [destination]);
}
if (destination + fileName === uri) {

@@ -130,0 +132,0 @@ onFail(FileError.INVALID_MODIFICATION_ERR);

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

__format__: function(fullPath) {
var path;
switch (this.name) {

@@ -34,0 +35,0 @@ case 'temporary':

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

var resolve = cordova.require('cordova-plugin-file.resolveLocalFileSystemURIProxy'),
info = require('cordova-plugin-file.bb10FileSystemInfo'),
requestAnimationFrame = cordova.require('cordova-plugin-file.bb10RequestAnimationFrame'),

@@ -37,0 +36,0 @@ createEntryFromNative = cordova.require('cordova-plugin-file.bb10CreateEntryFromNative');

@@ -42,2 +42,2 @@ /*

]);
}
};

@@ -59,3 +59,3 @@ /*

reader.onloadend = function () {
var contents = new Uint8Array(this.result).subarray(0, length);
var contents = new Uint8Array(this.result).subarray(0, length),
blob = new Blob([contents]);

@@ -62,0 +62,0 @@ window.requestAnimationFrame(function () {

@@ -43,3 +43,3 @@ /*

offset = args[2],
isBinary = args[3],
//isBinary = args[3],
onSuccess = function (data) {

@@ -46,0 +46,0 @@ if (typeof success === 'function') {

@@ -101,3 +101,5 @@ /*

// cdvfile other than local file resource is not supported
fail && fail(new FileError(FileError.ENCODING_ERR));
if (fail) {
fail(new FileError(FileError.ENCODING_ERR));
}
} else {

@@ -139,3 +141,5 @@ nativeResolveLocalFileSystemURL(url, win, fail);

entryType.setMetadata = function(win, fail /*, metadata*/) {
fail && fail("Not supported");
if (fail) {
fail("Not supported");
}
};

@@ -142,0 +146,0 @@

@@ -112,4 +112,3 @@ /*

};
var filesystem = this.filesystem,
srcURL = this.toInternalURL(),
var srcURL = this.toInternalURL(),
// entry name

@@ -129,3 +128,5 @@ name = newName || this.name,

// no Entry object returned
fail && fail(FileError.NOT_FOUND_ERR);
if (fail) {
fail(FileError.NOT_FOUND_ERR);
}
}

@@ -155,4 +156,3 @@ };

};
var filesystem = this.filesystem,
srcURL = this.toInternalURL(),
var srcURL = this.toInternalURL(),
// entry name

@@ -173,3 +173,5 @@ name = newName || this.name,

// no Entry object returned
fail && fail(FileError.NOT_FOUND_ERR);
if (fail) {
fail(FileError.NOT_FOUND_ERR);
}
}

@@ -176,0 +178,0 @@ };

@@ -39,3 +39,11 @@ /*

var FileEntry = function(name, fullPath, fileSystem, nativeURL) {
FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath, fileSystem, nativeURL]);
// remove trailing slash if it is present
if (fullPath && /\/$/.test(fullPath)) {
fullPath = fullPath.substring(0, fullPath.length - 1);
}
if (nativeURL && /\/$/.test(nativeURL)) {
nativeURL = nativeURL.substring(0, nativeURL.length - 1);
}
FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath, fileSystem, nativeURL]);
};

@@ -56,5 +64,9 @@

if (writer.localURL === null || writer.localURL === "") {
errorCallback && errorCallback(new FileError(FileError.INVALID_STATE_ERR));
if (errorCallback) {
errorCallback(new FileError(FileError.INVALID_STATE_ERR));
}
} else {
successCallback && successCallback(writer);
if (successCallback) {
successCallback(writer);
}
}

@@ -61,0 +73,0 @@ }, errorCallback);

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

utils = require('cordova/utils'),
File = require('./File'),
FileError = require('./FileError'),

@@ -43,2 +42,3 @@ ProgressEvent = require('./ProgressEvent'),

this._result = null;
this._progress = null;
this._localURL = '';

@@ -48,2 +48,10 @@ this._realReader = origFileReader ? new origFileReader() : {};

/**
* Defines the maximum size to read at a time via the native API. The default value is a compromise between
* minimizing the overhead of many exec() calls while still reporting progress frequently enough for large files.
* (Note attempts to allocate more than a few MB of contiguous memory on the native side are likely to cause
* OOM exceptions, while the JS engine seems to have fewer problems managing large strings or ArrayBuffers.)
*/
FileReader.READ_CHUNK_SIZE = 256*1024;
// States

@@ -88,2 +96,3 @@ FileReader.EMPTY = 0;

reader._error = null;
reader._progress = 0;
reader._readyState = FileReader.LOADING;

@@ -98,6 +107,80 @@

reader.onloadstart && reader.onloadstart(new ProgressEvent("loadstart", {target:reader}));
if (reader.onloadstart) {
reader.onloadstart(new ProgressEvent("loadstart", {target:reader}));
}
}
/**
* Callback used by the following read* functions to handle incremental or final success.
* Must be bound to the FileReader's this along with all but the last parameter,
* e.g. readSuccessCallback.bind(this, "readAsText", "UTF-8", offset, totalSize, accumulate)
* @param readType The name of the read function to call.
* @param encoding Text encoding, or null if this is not a text type read.
* @param offset Starting offset of the read.
* @param totalSize Total number of bytes or chars to read.
* @param accumulate A function that takes the callback result and accumulates it in this._result.
* @param r Callback result returned by the last read exec() call, or null to begin reading.
*/
function readSuccessCallback(readType, encoding, offset, totalSize, accumulate, r) {
if (this._readyState === FileReader.DONE) {
return;
}
if (typeof r !== "undefined") {
accumulate(r);
this._progress = Math.min(this._progress + FileReader.READ_CHUNK_SIZE, totalSize);
if (typeof this.onprogress === "function") {
this.onprogress(new ProgressEvent("progress", {loaded:this._progress, total:totalSize}));
}
}
if (typeof r === "undefined" || this._progress < totalSize) {
var execArgs = [
this._localURL,
offset + this._progress,
offset + this._progress + Math.min(totalSize - this._progress, FileReader.READ_CHUNK_SIZE)];
if (encoding) {
execArgs.splice(1, 0, encoding);
}
exec(
readSuccessCallback.bind(this, readType, encoding, offset, totalSize, accumulate),
readFailureCallback.bind(this),
"File", readType, execArgs);
} else {
this._readyState = FileReader.DONE;
if (typeof this.onload === "function") {
this.onload(new ProgressEvent("load", {target:this}));
}
if (typeof this.onloadend === "function") {
this.onloadend(new ProgressEvent("loadend", {target:this}));
}
}
}
/**
* Callback used by the following read* functions to handle errors.
* Must be bound to the FileReader's this, e.g. readFailureCallback.bind(this)
*/
function readFailureCallback(e) {
if (this._readyState === FileReader.DONE) {
return;
}
this._readyState = FileReader.DONE;
this._result = null;
this._error = new FileError(e);
if (typeof this.onerror === "function") {
this.onerror(new ProgressEvent("error", {target:this}));
}
if (typeof this.onloadend === "function") {
this.onloadend(new ProgressEvent("loadend", {target:this}));
}
}
/**
* Abort reading file.

@@ -140,56 +223,10 @@ */

var enc = encoding ? encoding : "UTF-8";
var me = this;
var execArgs = [this._localURL, enc, file.start, file.end];
// Read file
exec(
// Success callback
function(r) {
// If DONE (cancelled), then don't do anything
if (me._readyState === FileReader.DONE) {
return;
}
// DONE state
me._readyState = FileReader.DONE;
// Save result
me._result = r;
// If onload callback
if (typeof me.onload === "function") {
me.onload(new ProgressEvent("load", {target:me}));
}
// If onloadend callback
if (typeof me.onloadend === "function") {
me.onloadend(new ProgressEvent("loadend", {target:me}));
}
},
// Error callback
function(e) {
// If DONE (cancelled), then don't do anything
if (me._readyState === FileReader.DONE) {
return;
}
// DONE state
me._readyState = FileReader.DONE;
// null result
me._result = null;
// Save error
me._error = new FileError(e);
// If onerror callback
if (typeof me.onerror === "function") {
me.onerror(new ProgressEvent("error", {target:me}));
}
// If onloadend callback
if (typeof me.onloadend === "function") {
me.onloadend(new ProgressEvent("loadend", {target:me}));
}
}, "File", "readAsText", execArgs);
var totalSize = file.end - file.start;
readSuccessCallback.bind(this)("readAsText", enc, file.start, totalSize, function(r) {
if (this._progress === 0) {
this._result = "";
}
this._result += r;
}.bind(this));
};

@@ -210,55 +247,11 @@

var me = this;
var execArgs = [this._localURL, file.start, file.end];
// Read file
exec(
// Success callback
function(r) {
// If DONE (cancelled), then don't do anything
if (me._readyState === FileReader.DONE) {
return;
}
// DONE state
me._readyState = FileReader.DONE;
// Save result
me._result = r;
// If onload callback
if (typeof me.onload === "function") {
me.onload(new ProgressEvent("load", {target:me}));
}
// If onloadend callback
if (typeof me.onloadend === "function") {
me.onloadend(new ProgressEvent("loadend", {target:me}));
}
},
// Error callback
function(e) {
// If DONE (cancelled), then don't do anything
if (me._readyState === FileReader.DONE) {
return;
}
// DONE state
me._readyState = FileReader.DONE;
me._result = null;
// Save error
me._error = new FileError(e);
// If onerror callback
if (typeof me.onerror === "function") {
me.onerror(new ProgressEvent("error", {target:me}));
}
// If onloadend callback
if (typeof me.onloadend === "function") {
me.onloadend(new ProgressEvent("loadend", {target:me}));
}
}, "File", "readAsDataURL", execArgs);
var totalSize = file.end - file.start;
readSuccessCallback.bind(this)("readAsDataURL", null, file.start, totalSize, function(r) {
var commaIndex = r.indexOf(',');
if (this._progress === 0) {
this._result = r;
} else {
this._result += r.substring(commaIndex + 1);
}
}.bind(this));
};

@@ -276,54 +269,9 @@

var me = this;
var execArgs = [this._localURL, file.start, file.end];
// Read file
exec(
// Success callback
function(r) {
// If DONE (cancelled), then don't do anything
if (me._readyState === FileReader.DONE) {
return;
}
// DONE state
me._readyState = FileReader.DONE;
me._result = r;
// If onload callback
if (typeof me.onload === "function") {
me.onload(new ProgressEvent("load", {target:me}));
}
// If onloadend callback
if (typeof me.onloadend === "function") {
me.onloadend(new ProgressEvent("loadend", {target:me}));
}
},
// Error callback
function(e) {
// If DONE (cancelled), then don't do anything
if (me._readyState === FileReader.DONE) {
return;
}
// DONE state
me._readyState = FileReader.DONE;
me._result = null;
// Save error
me._error = new FileError(e);
// If onerror callback
if (typeof me.onerror === "function") {
me.onerror(new ProgressEvent("error", {target:me}));
}
// If onloadend callback
if (typeof me.onloadend === "function") {
me.onloadend(new ProgressEvent("loadend", {target:me}));
}
}, "File", "readAsBinaryString", execArgs);
var totalSize = file.end - file.start;
readSuccessCallback.bind(this)("readAsBinaryString", null, file.start, totalSize, function(r) {
if (this._progress === 0) {
this._result = "";
}
this._result += r;
}.bind(this));
};

@@ -341,59 +289,10 @@

var me = this;
var execArgs = [this._localURL, file.start, file.end];
// Read file
exec(
// Success callback
function(r) {
// If DONE (cancelled), then don't do anything
if (me._readyState === FileReader.DONE) {
return;
}
// DONE state
me._readyState = FileReader.DONE;
if (r instanceof Array) {
r = new Uint8Array(r).buffer;
}
me._result = r;
// If onload callback
if (typeof me.onload === "function") {
me.onload(new ProgressEvent("load", {target:me}));
}
// If onloadend callback
if (typeof me.onloadend === "function") {
me.onloadend(new ProgressEvent("loadend", {target:me}));
}
},
// Error callback
function(e) {
// If DONE (cancelled), then don't do anything
if (me._readyState === FileReader.DONE) {
return;
}
// DONE state
me._readyState = FileReader.DONE;
me._result = null;
// Save error
me._error = new FileError(e);
// If onerror callback
if (typeof me.onerror === "function") {
me.onerror(new ProgressEvent("error", {target:me}));
}
// If onloadend callback
if (typeof me.onloadend === "function") {
me.onloadend(new ProgressEvent("loadend", {target:me}));
}
}, "File", "readAsArrayBuffer", execArgs);
var totalSize = file.end - file.start;
readSuccessCallback.bind(this)("readAsArrayBuffer", null, file.start, totalSize, function(r) {
var resultArray = (this._progress === 0 ? new Uint8Array(totalSize) : new Uint8Array(this._result));
resultArray.set(new Uint8Array(r), this._progress);
this._result = resultArray.buffer;
}.bind(this));
};
module.exports = FileReader;

@@ -53,4 +53,4 @@ /*

return encodeURI(path).replace(/#/g, '%23');
}
};
module.exports = FileSystem;

@@ -29,2 +29,12 @@ /*

require('./fileSystems').getFs = function(name, callback) {
function success(response) {
fsMap = {};
for (var i = 0; i < response.length; ++i) {
var fsRoot = response[i];
var fs = new FileSystem(fsRoot.filesystemName, fsRoot);
fsMap[fs.name] = fs;
}
callback(fsMap[name]);
}
if (fsMap) {

@@ -34,13 +44,4 @@ callback(fsMap[name]);

exec(success, null, "File", "requestAllFileSystems", []);
function success(response) {
fsMap = {};
for (var i = 0; i < response.length; ++i) {
var fsRoot = response[i];
var fs = new FileSystem(fsRoot.filesystemName, fsRoot);
fsMap[fs.name] = fs;
}
callback(fsMap[name]);
}
}
};

@@ -97,4 +97,5 @@ /*

* @param data text or blob to be written
* @param isPendingBlobReadResult {Boolean} true if the data is the pending blob read operation result
*/
FileWriter.prototype.write = function(data) {
FileWriter.prototype.write = function(data, isPendingBlobReadResult) {

@@ -111,4 +112,25 @@ var that=this;

// Call this method again, with the arraybuffer as argument
FileWriter.prototype.write.call(that, this.result);
FileWriter.prototype.write.call(that, this.result, true /* isPendingBlobReadResult */);
};
fileReader.onerror = function () {
// DONE state
that.readyState = FileWriter.DONE;
// Save error
that.error = this.error;
// If onerror callback
if (typeof that.onerror === "function") {
that.onerror(new ProgressEvent("error", {"target":that}));
}
// If onwriteend callback
if (typeof that.onwriteend === "function") {
that.onwriteend(new ProgressEvent("writeend", {"target":that}));
}
};
// WRITING state
this.readyState = FileWriter.WRITING;
if (supportsBinary) {

@@ -130,3 +152,3 @@ fileReader.readAsArrayBuffer(data);

// Throw an exception if we are already writing a file
if (this.readyState === FileWriter.WRITING) {
if (this.readyState === FileWriter.WRITING && !isPendingBlobReadResult) {
throw new FileError(FileError.INVALID_STATE_ERR);

@@ -133,0 +155,0 @@ }

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

*/
(function() {

@@ -51,3 +52,5 @@ //For browser platform: not all browsers use this file.

var fail = function(code) {
errorCallback && errorCallback(new FileError(code));
if (errorCallback) {
errorCallback(new FileError(code));
}
};

@@ -54,0 +57,0 @@

@@ -51,3 +51,5 @@ /*

var fail = function(error) {
errorCallback && errorCallback(new FileError(error));
if (errorCallback) {
errorCallback(new FileError(error));
}
};

@@ -54,0 +56,0 @@ // sanity check for 'not:valid:filename' or '/not:valid:filename'

@@ -31,3 +31,3 @@ /*

if (successCallback) {
fs = new FileSystem(file_system.name, file_system.root);
var fs = new FileSystem(file_system.name, file_system.root);
successCallback(fs);

@@ -34,0 +34,0 @@ }

@@ -66,6 +66,6 @@ /*

data = new Uint8Array(data);
var binary = "";
for (var i = 0; i < data.byteLength; i++) {
var binary = "";
for (var i = 0; i < data.byteLength; i++) {
binary += String.fromCharCode(data[i]);
}
}
data = binary;

@@ -130,3 +130,3 @@ }

}, "File", "write", [path, data, this.position, isBinary]);
};
}

@@ -133,0 +133,0 @@ module.exports = {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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