From f0250c3cb342f103ec6adedda3c2726cff001613 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 25 Jul 2013 09:14:17 -0700 Subject: [PATCH] convert non-buffer objects first to strings --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4c00e7b..ea124bf 100644 --- a/index.js +++ b/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;