for (i = 0; i < list.length; ++i) {
const buf = list[i]
if (isInstance(buf, Uint8Array)) {
- Uint8Array.prototype.set.call(
- buffer,
- buf,
- pos
- )
+ if (pos + buf.length > buffer.length) {
+ Buffer.from(buf).copy(buffer, pos)
+ } else {
+ Uint8Array.prototype.set.call(
+ buffer,
+ buf,
+ pos
+ )
+ }
} else if (!Buffer.isBuffer(buf)) {
throw new TypeError('"list" argument must be an Array of Buffers')
} else {
t.end()
})
+test('concat() works on Uint8Array instances for smaller provided totalLength', function (t) {
+ const result = B.concat([new Uint8Array([1, 2]), new Uint8Array([3, 4])], 3)
+ const expected = B.from([1, 2, 3])
+ t.deepEqual(result, expected)
+ t.end()
+})
+
test('fill', function (t) {
const b = new B(10)
b.fill(2)