From 1b843e820796aa5ec9d9546c151d76f279aeac17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Thu, 22 Mar 2018 03:21:04 +0300 Subject: [PATCH] Avoid using deprecated Buffer API Use Buffer.from when it's available instead of 'new Bufer(string)' Fixes: https://github.com/npm/fstream/issues/60 Refs: https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor --- lib/collect.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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) }