diff --git a/lib/collect.js b/lib/collect.js index e5d4f35..6076d30 100644 --- a/lib/collect.js +++ b/lib/collect.js @@ -12,7 +12,15 @@ function collect (stream) { stream.on('end', save) var buf = [] function save (b) { - if (typeof b === 'string') b = new Buffer(b) + if (typeof b === 'string') { + if (Buffer.from && Buffer.from !== Uint8Array.from) { + b = Buffer.from(b) + } else { + // Outdated Node.js versions (<4.5.0 or 5.x <5.10) + // b is already type-checked to be a string just above + b = new Buffer(b) + } + } if (Buffer.isBuffer(b) && !b.length) return buf.push(b) }