cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dase...@apache.org
Subject cordova-plugin-file git commit: CB-10960 Uncaught #<FileError> in write() when readyState != WRITING ?
Date Mon, 11 Apr 2016 07:37:14 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master c13b59139 -> 0e4971543


CB-10960 Uncaught #<FileError> in write() when readyState != WRITING ?


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/0e497154
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/0e497154
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/0e497154

Branch: refs/heads/master
Commit: 0e4971543fd4006018275441812b5e5bb18a4fa0
Parents: c13b591
Author: daserge <v-seshak@microsoft.com>
Authored: Thu Apr 7 12:06:14 2016 +0300
Committer: daserge <v-seshak@microsoft.com>
Committed: Mon Apr 11 09:49:18 2016 +0300

----------------------------------------------------------------------
 www/FileWriter.js | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/0e497154/www/FileWriter.js
----------------------------------------------------------------------
diff --git a/www/FileWriter.js b/www/FileWriter.js
index 7f53c0c..a3c686f 100644
--- a/www/FileWriter.js
+++ b/www/FileWriter.js
@@ -94,8 +94,9 @@ FileWriter.prototype.abort = function() {
  * Writes data to the file
  *
  * @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) {
 
     var that=this;
     var supportsBinary = (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer
!== 'undefined');
@@ -107,8 +108,29 @@ FileWriter.prototype.write = function(data) {
         var fileReader = new FileReader();
         fileReader.onload = function() {
             // 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) {
             fileReader.readAsArrayBuffer(data);
         } else {
@@ -125,7 +147,7 @@ FileWriter.prototype.write = function(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);
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message