Buffer

# Buffer

import { Buffer } from 'node:buffer';

# Buffer.concat(list[, length])

返回一个新的,它是将所有 实例连接在一起Buffer的结果。Bufferlist

如果列表没有项目,或者如果 是0,则返回totalLength一个新的零长度 。Buffer

如果totalLength未提供,则通过添加它们的长度Buffer从中的实例计算得出list。

如果totalLength提供,它将被强制为无符号整数。Buffer如果s in的组合长度list超过totalLength,则结果将被截断为totalLength。

import { Buffer } from 'node:buffer';

// Create a single `Buffer` from a list of three `Buffer` instances.

const buf1 = Buffer.alloc(10);
const buf2 = Buffer.alloc(14);
const buf3 = Buffer.alloc(18);
const totalLength = buf1.length + buf2.length + buf3.length;

console.log(totalLength);
// Prints: 42

const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);

console.log(bufA);
// Prints: <Buffer 00 00 00 00 ...>
console.log(bufA.length);
// Prints: 42