incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tim...@apache.org
Subject [21/48] js commit: filereader now reads dataasurl properly
Date Thu, 07 Jun 2012 20:40:44 GMT
filereader now reads dataasurl properly


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/72e6d1ee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/72e6d1ee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/72e6d1ee

Branch: refs/heads/master
Commit: 72e6d1ee1f2a523af02558513969c1afe704ad89
Parents: 24596e7
Author: Tim Kim <tim.kim@nitobi.com>
Authored: Wed May 30 16:16:44 2012 -0700
Committer: Tim Kim <tim.kim@nitobi.com>
Committed: Thu Jun 7 13:40:23 2012 -0700

----------------------------------------------------------------------
 lib/playbook/plugin/playbook/FileReader.js |   81 +++++++++++------------
 1 files changed, 39 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/72e6d1ee/lib/playbook/plugin/playbook/FileReader.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/FileReader.js b/lib/playbook/plugin/playbook/FileReader.js
index 475b860..564f717 100644
--- a/lib/playbook/plugin/playbook/FileReader.js
+++ b/lib/playbook/plugin/playbook/FileReader.js
@@ -166,60 +166,57 @@ FileReader.prototype.readAsDataURL = function(file) {
         this.onloadstart(new ProgressEvent("loadstart", {target:this}));
     }
 
+    var enc = "BASE64";
+
     var me = this;
-    console.log('read as url');
+
     // Read file
-    /*
-    exec(
-        // Success callback
-        function(r) {
-            // If DONE (cancelled), then don't do anything
-            if (me.readyState === FileReader.DONE) {
-                return;
-            }
+    if(blackberry.io.file.exists(this.fileName)){
+        var theText = '';
+        var getFileContents = function(path,blob){
+            if(blob){
 
-            // DONE state
-            me.readyState = FileReader.DONE;
+                theText = blackberry.utils.blobToString(blob, enc);
+                me.result = "data:text/plain;base64," +theText;
 
-            // Save result
-            me.result = r;
+                if (typeof me.onload === "function") {
+                    me.onload(new ProgressEvent("load", {target:me}));
+                }
 
-            // If onload callback
-            if (typeof me.onload === "function") {
-                me.onload(new ProgressEvent("load", {target:me}));
-            }
+                me.readyState = FileReader.DONE;
 
-            // 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;
+                if (typeof me.onloadend === "function") {
+                    me.onloadend(new ProgressEvent("loadend", {target:me}));
+                }
             }
+        }
+        // setting asynch to off - worry about making this all callbacks later
+        blackberry.io.file.readFile(this.fileName, getFileContents, false);
 
-            // DONE state
-            me.readyState = FileReader.DONE;
+    }else{
+        // If DONE (cancelled), then don't do anything
+        if (me.readyState === FileReader.DONE) {
+            return;
+        }
 
-            me.result = null;
+        // DONE state
+        me.readyState = FileReader.DONE;
 
-            // Save error
-            me.error = new FileError(e);
+        me.result = null;
 
-            // If onerror callback
-            if (typeof me.onerror === "function") {
-                me.onerror(new ProgressEvent("error", {target:me}));
-            }
+        // Save error
+        me.error = new FileError(FileError.NOT_FOUND_ERR);
 
-            // If onloadend callback
-            if (typeof me.onloadend === "function") {
-                me.onloadend(new ProgressEvent("loadend", {target:me}));
-            }
-        }, "File", "readAsDataURL", [this.fileName]);
-    */
+        // 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}));
+        }
+    }
 };
 
 /**


Mime
View raw message