Skip to content

Commit

Permalink
Buffer.concat() accepts Uint8Array instances
Browse files Browse the repository at this point in the history
Fix #173
  • Loading branch information
feross committed Feb 16, 2018
1 parent fb31047 commit 42201a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
7 changes: 7 additions & 0 deletions test/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 42201a7

Please sign in to comment.