re-apply readAsBinaryString and readAsArrayBuffer

Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/0788b708
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/0788b708
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/0788b708

Branch: refs/heads/master
Commit: 0788b708de23c08ab56a34f05d7acd8773feb998
Parents: 44b2a07
Author: Jesse MacFadyen <[email protected]>
Authored: Tue Jul 8 18:06:40 2014 -0700
Committer: Jesse MacFadyen <[email protected]>
Committed: Tue Jul 8 18:06:40 2014 -0700

----------------------------------------------------------------------
 src/windows8/FileProxy.js | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/0788b708/src/windows8/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/FileProxy.js b/src/windows8/FileProxy.js
index 0c722d1..b8830ab 100644
--- a/src/windows8/FileProxy.js
+++ b/src/windows8/FileProxy.js
@@ -190,11 +190,49 @@ module.exports = {
             });
     },
 
+    readAsBinaryString:function(win,fail,args) {
+        var fileName = cordovaPathToNative((args[0]);
+
+        getFileFromPathAsync(fileName).then(
+            function (storageFile) {
+                Windows.Storage.FileIO.readBufferAsync(storageFile).done(
+                    function (buffer) {
+                        var dataReader = 
Windows.Storage.Streams.DataReader.fromBuffer(buffer);
+                        var fileContent = dataReader.readString(buffer.length);
+                        dataReader.close();
+                        win(fileContent);
+                    }
+                );
+            }, function () {
+                fail && fail(FileError.NOT_FOUND_ERR);
+            }
+        );
+    },
+
+    readAsArrayBuffer:function(win,fail,args) {
+        var fileName =cordovaPathToNative(args[0]);
+
+        getFileFromPathAsync(fileName).then(
+            function (storageFile) {
+                var blob = MSApp.createFileFromStorageFile(storageFile);
+                var url = URL.createObjectURL(blob, { oneTimeOnly: true });
+                var xhr = new XMLHttpRequest();
+                xhr.open("GET", url, true);
+                xhr.responseType = 'arraybuffer';
+                xhr.onload = function() {
+                    win(xhr.response);
+                };
+                xhr.send();
+            }, function () {
+                fail && fail(FileError.NOT_FOUND_ERR);
+            }
+        );
+    },
+
     readAsDataURL: function (win, fail, args) {
 
         var fileName = cordovaPathToNative(args[0]);
 
-
         getFileFromPathAsync(fileName).then(
             function (storageFile) {
                 Windows.Storage.FileIO.readBufferAsync(storageFile).done(

Reply via email to