handle actual binary, not just utf8

This commit is contained in:
AJ ONeal 2012-09-19 14:22:55 -06:00
parent b51cbf6c06
commit 93ce8ddd9f
3 changed files with 25 additions and 4 deletions

19
README.md Normal file
View File

@ -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.

View File

@ -18,5 +18,6 @@
"btoa": "bin/btoa.js"
},
"main": "index",
"version": "1.0.1"
"license": "Apache2",
"version": "1.1.0"
}

View File

@ -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;
}