cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [02/25] js commit: CB 4004: Adding base64 encoding for array buffers, while removing the String expansion (cherry picked from commit 5ba835cf64a50f48dcdc8ced49fed1a714c098cc)
Date Tue, 22 Oct 2013 15:45:12 GMT
CB 4004: Adding base64 encoding for array buffers, while removing the String expansion
(cherry picked from commit 5ba835cf64a50f48dcdc8ced49fed1a714c098cc)


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

Branch: refs/heads/2.9.x
Commit: 082a72532a446b4e9168afa42c12f9d408814bbe
Parents: a750db7
Author: Chris Barton <c.chris.b@gmail.com>
Authored: Wed Jun 26 11:23:29 2013 -0700
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Tue Oct 22 11:33:52 2013 -0400

----------------------------------------------------------------------
 lib/android/exec.js |  3 ++-
 test/test.base64.js | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/082a7253/lib/android/exec.js
----------------------------------------------------------------------
diff --git a/lib/android/exec.js b/lib/android/exec.js
index 206c09a..f55b5ad 100644
--- a/lib/android/exec.js
+++ b/lib/android/exec.js
@@ -36,6 +36,7 @@
 var cordova = require('cordova'),
     nativeApiProvider = require('cordova/plugin/android/nativeapiprovider'),
     utils = require('cordova/utils'),
+    base64 = require('cordova/base64'),
     jsToNativeModes = {
         PROMPT: 0,
         JS_OBJECT: 1,
@@ -74,7 +75,7 @@ function androidExec(success, fail, service, action, args) {
     // Process any ArrayBuffers in the args into a string.
     for (var i = 0; i < args.length; i++) {
         if (utils.typeName(args[i]) == 'ArrayBuffer') {
-            args[i] = window.btoa(String.fromCharCode.apply(null, new Uint8Array(args[i])));
+            args[i] = utils.encodeBase64(args[i]);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/082a7253/test/test.base64.js
----------------------------------------------------------------------
diff --git a/test/test.base64.js b/test/test.base64.js
index 666cafe..f9b1912 100644
--- a/test/test.base64.js
+++ b/test/test.base64.js
@@ -47,4 +47,17 @@ describe("base64", function () {
 
       expect(base64.fromArrayBuffer(arrayBuffer)).toBe(base64string);
     });
+
+    it("can base64 encode an text string in an ArrayBuffer", function () {
+      var buffer = new Buffer('Some Awesome Test This Is!', 'binary')
+        , base64string = buffer.toString('base64')
+        , arrayBuffer = new ArrayBuffer(buffer.length)
+        , view = new Uint8Array(arrayBuffer);
+
+      for (var i = 0; i < buffer.length; i++) {
+        view[i] = buffer[i];
+      }
+
+      expect(base64.fromArrayBuffer(arrayBuffer)).toBe(base64string);
+    });
 });


Mime
View raw message