From c1673f281cb5e4a088f12a80bac4536be0b44215 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 --- atob/README.md | 19 +++++++++++++++++++ atob/package.json | 3 ++- atob/test.js | 7 ++++++- btoa/README.md | 19 +++++++++++++++++++ btoa/package.json | 3 ++- btoa/test.js | 7 ++++--- 6 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 atob/README.md create mode 100644 btoa/README.md diff --git a/atob/README.md b/atob/README.md new file mode 100644 index 0000000..5f43a23 --- /dev/null +++ b/atob/README.md @@ -0,0 +1,19 @@ +atob +=== + +Uses `Buffer` to emulate the exact functionality of the browser's atob. + +Note: Unicode may be handled incorrectly (like the browser). + +It turns base64-encoded **a**scii data back **to** **b**inary. + + (function () { + "use strict"; + + var atob = require('atob') + , b64 = "SGVsbG8gV29ybGQ=" + , bin = atob(b64) + ; + + console.log(bin); // "Hello World" + }()); diff --git a/atob/package.json b/atob/package.json index 6077faa..1dd9948 100644 --- a/atob/package.json +++ b/atob/package.json @@ -18,5 +18,6 @@ "bin": { "atob": "bin/atob.js" }, - "version": "1.0.1" + "license": "Apache2", + "version": "1.1.0" } diff --git a/atob/test.js b/atob/test.js index 38e5ffe..f8903d0 100644 --- a/atob/test.js +++ b/atob/test.js @@ -1,13 +1,18 @@ +/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/ (function () { "use strict"; var atob = require('./index') , encoded = "SGVsbG8gV29ybGQ=" , unencoded = "Hello World" - , result + /* + , encoded = "SGVsbG8sIBZM" + , unencoded = "Hello, 世界" + */ ; if (unencoded !== atob(encoded)) { + console.log('[FAIL]', unencoded, atob(encoded)); return; } diff --git a/btoa/README.md b/btoa/README.md new file mode 100644 index 0000000..4a03995 --- /dev/null +++ b/btoa/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/btoa/package.json b/btoa/package.json index 206945e..6c900e1 100644 --- a/btoa/package.json +++ b/btoa/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/btoa/test.js b/btoa/test.js index e0122a2..d57f94e 100644 --- a/btoa/test.js +++ b/btoa/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; }