incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tim...@apache.org
Subject [8/19] js commit: file reads as text now
Date Thu, 17 May 2012 22:37:07 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/1af4b05c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/1af4b05c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/1af4b05c

Branch: refs/heads/playbookFile
Commit: 1af4b05c33b3532134949153085f5c7c7f72a7f0
Parents: 58943e2
Author: Tim Kim <timk@adobe.com>
Authored: Thu May 10 13:44:43 2012 -0700
Committer: Tim Kim <timk@adobe.com>
Committed: Thu May 10 13:44:43 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/1af4b05c/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