Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,25 +614,53 @@ Buffer.concat = function concat(list, length) {
if (length === undefined) {
length = 0;
for (let i = 0; i < list.length; i++) {
if (list[i].length) {
length += list[i].length;
const buf = list[i];
if (!isUint8Array(buf)) {
// TODO(BridgeAR): This should not be of type ERR_INVALID_ARG_TYPE.
// Instead, find the proper error code for this.
throw new ERR_INVALID_ARG_TYPE(
`list[${i}]`, ['Buffer', 'Uint8Array'], buf);
}
Comment thread
gurgunday marked this conversation as resolved.
length += buf.length;
Comment thread
mertcanaltin marked this conversation as resolved.
Outdated
}
} else {
validateOffset(length, 'length');

const buffer = allocate(length);
let pos = 0;
for (let i = 0; i < list.length; i++) {
const buf = list[i];
TypedArrayPrototypeSet(buffer, buf, pos);
pos += buf.length;
}

if (pos < length) {
TypedArrayPrototypeFill(buffer, 0, pos, length);
}
Comment thread
mertcanaltin marked this conversation as resolved.
Comment thread
mertcanaltin marked this conversation as resolved.
return buffer;
}

const buffer = Buffer.allocUnsafe(length);
let pos = 0;
validateOffset(length, 'length');
for (let i = 0; i < list.length; i++) {
const buf = list[i];
if (!isUint8Array(buf)) {
if (!isUint8Array(list[i])) {
// TODO(BridgeAR): This should not be of type ERR_INVALID_ARG_TYPE.
// Instead, find the proper error code for this.
throw new ERR_INVALID_ARG_TYPE(
`list[${i}]`, ['Buffer', 'Uint8Array'], list[i]);
}
pos += _copyActual(buf, buffer, pos, 0, buf.length, true);
}

const buffer = allocate(length);
let pos = 0;
for (let i = 0; i < list.length; i++) {
const buf = list[i];
if (pos + buf.length > length) {
TypedArrayPrototypeSet(buffer,
TypedArrayPrototypeSlice(buf, 0, length - pos),
Comment thread
mertcanaltin marked this conversation as resolved.
Outdated
pos);
pos = length;
break;
}
TypedArrayPrototypeSet(buffer, buf, pos);
pos += buf.length;
}

// Note: `length` is always equal to `buffer.length` at this point
Expand Down
Loading