incubator-callback-commits mailing list archives

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


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/00e7bbef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/00e7bbef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/00e7bbef

Branch: refs/heads/master
Commit: 00e7bbef3ec6319df575aec75c2f4ec1ca8f14bf
Parents: 73edeb8
Author: Tim Kim <timk@adobe.com>
Authored: Thu May 10 13:44:43 2012 -0700
Committer: Tim Kim <tim.kim@nitobi.com>
Committed: Thu Jun 7 13:40:22 2012 -0700

----------------------------------------------------------------------
 lib/playbook/plugin/playbook/FileReader.js |   75 +++++++----------------
 1 files changed, 23 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/00e7bbef/lib/playbook/plugin/playbook/FileReader.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/FileReader.js b/lib/playbook/plugin/playbook/FileReader.js
index da890f9..0fa4918 100644
--- a/lib/playbook/plugin/playbook/FileReader.js
+++ b/lib/playbook/plugin/playbook/FileReader.js
@@ -88,63 +88,34 @@ FileReader.prototype.readAsText = function(file, encoding) {
     var enc = encoding ? encoding : "UTF-8";
 
     var me = this;
-    console.log('read as text');
-    if(blackberry.io.file.exists(this.fileName)){
-
-    }
     // Read file
-    /*
-    exec(
-        // Success callback
-        function(r) {
-            // If DONE (cancelled), then don't do anything
-            if (me.readyState === FileReader.DONE) {
-                return;
-            }
-
-            // Save result
-            me.result = r;
-
-            // If onload callback
-            if (typeof me.onload === "function") {
-                me.onload(new ProgressEvent("load", {target:me}));
-            }
-
-            // DONE state
-            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(blackberry.io.file.exists(this.fileName)){
+        var theText = '';
+        var getFileContents = function(path,blob){
+            if(blob){
+            
+                theText = blackberry.utils.blobToString(blob);
+                me.result = theText;
+                
+                if (typeof me.onload === "function") {
+                    me.onload(new ProgressEvent("load", {target:me}));
+                }
+                
+                me.readyState = FileReader.DONE;
+
+                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{
 
-            // null result
-            me.result = null;
+        // TODO: file doesn't exist - throw error
 
-            // 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", [this.fileName, enc]);
-    */
+    }
 };
 
 


Mime
View raw message