From 8b15697a1016b80e34526efeb19275d53b534619 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 --- btoa/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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;