You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/05/07 17:16:37 UTC

[21/32] js commit: [BlackBerry10] FileReader - handle case where native file object is passed in

[BlackBerry10] FileReader - handle case where native file object is passed in

Reviewed by Jeffrey Heifetz <jh...@blackberry.com>
Tested by Tracy Li <tl...@blackberry.com>


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

Branch: refs/heads/future
Commit: 369e1aff171ee589366cc79d0736991dc5e23536
Parents: 5be2dab
Author: Bryan Higgins <bh...@blackberry.com>
Authored: Thu Apr 18 13:49:57 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Fri May 3 09:50:04 2013 -0400

----------------------------------------------------------------------
 lib/blackberry10/plugin/FileReader.js |   40 +++++++++++----------------
 1 files changed, 16 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/369e1aff/lib/blackberry10/plugin/FileReader.js
----------------------------------------------------------------------
diff --git a/lib/blackberry10/plugin/FileReader.js b/lib/blackberry10/plugin/FileReader.js
index c806b3f..17214ef 100644
--- a/lib/blackberry10/plugin/FileReader.js
+++ b/lib/blackberry10/plugin/FileReader.js
@@ -58,40 +58,32 @@ FileReader.prototype.abort = function() {
     return this.nativeReader.abort();
 };
 
+function read(method, context, file, encoding) {
+    if (file.fullPath) {
+         fileUtils.getEntryForURI(file.fullPath, function (entry) {
+            entry.nativeEntry.file(function (nativeFile) {
+                context.nativeReader[method].call(context.nativeReader, nativeFile, encoding);
+            }, context.onerror);
+        }, context.onerror);
+    } else {
+        context.nativeReader[method](file, encoding);
+    }
+}
+
 FileReader.prototype.readAsText = function(file, encoding) {
-    var that = this;
-    fileUtils.getEntryForURI(file.fullPath, function (entry) {
-        entry.nativeEntry.file(function (nativeFile) {
-            that.nativeReader.readAsText(nativeFile, encoding);
-        }, that.onerror);
-    }, that.onerror);
+    read("readAsText", this, file, encoding);
 };
 
 FileReader.prototype.readAsDataURL = function(file) {
-    var that = this;
-    fileUtils.getEntryForURI(file.fullPath, function (entry) {
-        entry.nativeEntry.file(function (nativeFile) {
-            that.nativeReader.readAsDataURL(nativeFile);
-        }, that.onerror);
-    }, that.onerror);
+    read("readAsDataURL", this, file);
 };
 
 FileReader.prototype.readAsBinaryString = function(file) {
-    var that = this;
-    fileUtils.getEntryForURI(file.fullPath, function (entry) {
-        entry.nativeEntry.file(function (nativeFile) {
-            that.nativeReader.readAsBinaryString(nativeFile);
-        }, that.onerror);
-    }, that.onerror);
+    read("readAsBinaryString", this, file);
 };
 
 FileReader.prototype.readAsArrayBuffer = function(file) {
-    var that = this;
-    fileUtils.getEntryForURI(file.fullPath, function (entry) {
-        entry.nativeEntry.file(function (nativeFile) {
-            that.nativeReader.readAsArrayBuffer(nativeFile);
-        }, that.onerror);
-    }, that.onerror);
+    read("readAsArrayBuffer", this, file);
 };
 
 window.FileReader = FileReader;