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); + } }