You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ti...@apache.org on 2012/06/07 22:40:44 UTC
[33/48] js commit: file reads as text now
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 <ti...@adobe.com>
Authored: Thu May 10 13:44:43 2012 -0700
Committer: Tim Kim <ti...@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]);
- */
+ }
};