handle actual binary, not just utf8
This commit is contained in:
parent
b35a566ac6
commit
543a61a941
|
@ -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"
|
||||||
|
}());
|
|
@ -18,5 +18,6 @@
|
||||||
"bin": {
|
"bin": {
|
||||||
"atob": "bin/atob.js"
|
"atob": "bin/atob.js"
|
||||||
},
|
},
|
||||||
"version": "1.0.1"
|
"license": "Apache2",
|
||||||
|
"version": "1.1.0"
|
||||||
}
|
}
|
||||||
|
|
7
test.js
7
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 () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var atob = require('./index')
|
var atob = require('./index')
|
||||||
, encoded = "SGVsbG8gV29ybGQ="
|
, encoded = "SGVsbG8gV29ybGQ="
|
||||||
, unencoded = "Hello World"
|
, unencoded = "Hello World"
|
||||||
, result
|
/*
|
||||||
|
, encoded = "SGVsbG8sIBZM"
|
||||||
|
, unencoded = "Hello, 世界"
|
||||||
|
*/
|
||||||
;
|
;
|
||||||
|
|
||||||
if (unencoded !== atob(encoded)) {
|
if (unencoded !== atob(encoded)) {
|
||||||
|
console.log('[FAIL]', unencoded, atob(encoded));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue