diff --git a/btoa/index.js b/btoa/index.js index 4c00e7b..ea124bf 100644 --- a/btoa/index.js +++ b/btoa/index.js @@ -2,7 +2,16 @@ "use strict"; function btoa(str) { - return new Buffer(str.toString(), 'binary').toString('base64'); + var buffer + ; + + if (str instanceof Buffer) { + buffer = str; + } else { + buffer = new Buffer(str.toString(), 'binary'); + } + + return buffer.toString('base64'); } module.exports = btoa;