From a769d8509885422b95c6f933e8088f92e0c0d6be Mon Sep 17 00:00:00 2001 From: cxam Date: Wed, 2 Aug 2017 16:09:27 +0100 Subject: [PATCH] Handle Buffer.from TypeError on pre node v4.5.x --- lib/utils.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 8aff277634..b936bb35da 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -162,5 +162,18 @@ function asBuffer(thing) { return thing; } - return Buffer.from ? Buffer.from(thing) : new Buffer(thing); + if (Buffer.from) { + // Buffer.from fix for node versions prior to 4.5.x + try { + return Buffer.from(thing); + } catch (e) { + if (e instanceof TypeError) { + return new Buffer(thing); + } else { + throw e; + } + } + } else { + return new Buffer(thing); + } }