lib/buffer-util.js
function concat(list, totalLength) {
  if (list.length === 0) return EMPTY_BUFFER;
  if (list.length === 1) return list[0];

  const target = Buffer.allocUnsafe(totalLength);
  let offset = 0;

  for (let i = 0; i < list.length; i++) {
    const buf = list[i];
    buf.copy(target, offset);
    offset += buf.length;
  }

  return target;
}
function concat(list, totalLength) {
  if (list.length === 0) return EMPTY_BUFFER;
  if (list.length === 1) return list[0];

  const target = Buffer.allocUnsafe(totalLength);
  let offset = 0;

  for (let i = 0; i < list.length; i++) {
    const buf = list[i];
    buf.copy(target, offset);
    offset += buf.length;
  }

  return target;
}
function concat ( list , totalLength ) { if ( list . length === 0 ) return EMPTY_BUFFER ; if ( list . length === 1 ) return list [ 0 ] ; const target = Buffer . allocUnsafe ( totalLength ) ; let offset = 0 ; for ( let i = 0 ; i < list . length ; i ++ ) { const buf = list [ i ] ; buf . copy ( target , offset ) ; offset += buf . length ; } return target ; }
Merges an array of buffers into a new buffer.

@param {Buffer[]} list The array of buffers to concat
@param {Number} totalLength The total length of buffers in the list
@return {Buffer} The resulting buffer
@public
Merges an array of buffers into a new buffer .