From 42201a7dbf66c2ac45270c85285d1b00a06fd58a Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 15 Feb 2018 23:09:57 -0800 Subject: [PATCH] Buffer.concat() accepts Uint8Array instances Fix https://github.com/feross/buffer/issues/173 --- index.js | 3 +++ test/methods.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/index.js b/index.js index a5b9ef5..19a9978 100644 --- a/index.js +++ b/index.js @@ -369,6 +369,9 @@ Buffer.concat = function concat (list, length) { var pos = 0 for (i = 0; i < list.length; ++i) { var buf = list[i] + if (isArrayBufferView(buf)) { + buf = Buffer.from(buf) + } if (!Buffer.isBuffer(buf)) { throw new TypeError('"list" argument must be an Array of Buffers') } diff --git a/test/methods.js b/test/methods.js index 3696437..a63e4c4 100644 --- a/test/methods.js +++ b/test/methods.js @@ -60,6 +60,13 @@ test('concat() a varying number of buffers', function (t) { t.end() }) +test('concat() works on Uint8Array instances', function (t) { + var result = B.concat([new Uint8Array([1, 2]), new Uint8Array([3, 4])]) + var expected = Buffer.from([1, 2, 3, 4]) + t.deepEqual(result, expected) + t.end() +}) + test('fill', function (t) { var b = new B(10) b.fill(2) -- 2.34.1