Skip to content

Commit 42201a7

Browse files
committed
Buffer.concat() accepts Uint8Array instances
Fix #173
1 parent fb31047 commit 42201a7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ Buffer.concat = function concat (list, length) {
369369
var pos = 0
370370
for (i = 0; i < list.length; ++i) {
371371
var buf = list[i]
372+
if (isArrayBufferView(buf)) {
373+
buf = Buffer.from(buf)
374+
}
372375
if (!Buffer.isBuffer(buf)) {
373376
throw new TypeError('"list" argument must be an Array of Buffers')
374377
}

test/methods.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ test('concat() a varying number of buffers', function (t) {
6060
t.end()
6161
})
6262

63+
test('concat() works on Uint8Array instances', function (t) {
64+
var result = B.concat([new Uint8Array([1, 2]), new Uint8Array([3, 4])])
65+
var expected = Buffer.from([1, 2, 3, 4])
66+
t.deepEqual(result, expected)
67+
t.end()
68+
})
69+
6370
test('fill', function (t) {
6471
var b = new B(10)
6572
b.fill(2)

0 commit comments

Comments
 (0)