From 93ce8ddd9f89a3fd1439f0d41028b949bdda0bc6 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 19 Sep 2012 14:22:55 -0600 Subject: [PATCH] handle actual binary, not just utf8 --- README.md | 19 +++++++++++++++++++ package.json | 3 ++- test.js | 7 ++++--- 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4a03995 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +btoa +=== + +Uses `Buffer` to emulate the exact functionality of the browser's btoa (except that it supports unicode and the browser may not). + +It turns **b**inary data **to** base64-encoded **a**scii. + + (function () { + "use strict"; + + var btoa = require('btoa') + , bin = "Hello, 世界" + , b64 = btoa(bin) + ; + + console.log(b64); // "SGVsbG8sIBZM" + }()); + +Note: Unicode may or may not be handled incorrectly. diff --git a/package.json b/package.json index 206945e..6c900e1 100644 --- a/package.json +++ b/package.json @@ -18,5 +18,6 @@ "btoa": "bin/btoa.js" }, "main": "index", - "version": "1.0.1" + "license": "Apache2", + "version": "1.1.0" } diff --git a/test.js b/test.js index e0122a2..d57f94e 100644 --- a/test.js +++ b/test.js @@ -1,13 +1,14 @@ +/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/ (function () { "use strict"; var btoa = require('./index') - , encoded = "SGVsbG8gV29ybGQ=" - , unencoded = "Hello World" - , result + , encoded = "SGVsbG8sIBZM" + , unencoded = "Hello, 世界" ; if (encoded !== btoa(unencoded)) { + console.error('[FAIL]', encoded, btoa(unencoded)); return; }