Skip to content

Commit

Permalink
handle actual binary, not just utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ ONeal committed Sep 19, 2012
1 parent ba6a628 commit c1673f2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
19 changes: 19 additions & 0 deletions atob/README.md
Original file line number Diff line number Diff line change
@@ -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"
}());
3 changes: 2 additions & 1 deletion atob/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"bin": {
"atob": "bin/atob.js"
},
"version": "1.0.1"
"license": "Apache2",
"version": "1.1.0"
}
7 changes: 6 additions & 1 deletion atob/test.js
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
19 changes: 19 additions & 0 deletions btoa/README.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion btoa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"btoa": "bin/btoa.js"
},
"main": "index",
"version": "1.0.1"
"license": "Apache2",
"version": "1.1.0"
}
7 changes: 4 additions & 3 deletions btoa/test.js
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down

0 comments on commit c1673f2

Please sign in to comment.