From 6de8e1665b11e3463b6aff90e82c712954edb181 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 16 Jul 2014 22:57:12 -0700 Subject: [PATCH] construct new buffer from buffer toJSON() output (fix #37) --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 746ecfd..1955cbc 100644 --- a/index.js +++ b/index.js @@ -61,9 +61,11 @@ function Buffer (subject, encoding, noZero) { if (encoding === 'base64') subject = base64clean(subject) length = Buffer.byteLength(subject, encoding) - } else if (type === 'object') // assume object is array-like + } else if (type === 'object' && subject !== null) { // assume object is array-like + if (subject.type === 'Buffer' && Array.isArray(subject.data)) + subject = subject.data length = +subject.length > 0 ? Math.floor(+subject.length) : 0 - else + } else throw new Error('First argument needs to be a number, array or string.') var buf -- 2.34.1