Buffer.concat(list[, totalLength])
Node.js FS模块方法速查
- list {Array} 需要连接的 Buffer 对象数组
- totalLength {Number} 上述需要被连接的 Buffer 的总大小。
- 返回:{Buffer}
const buf1 = Buffer.alloc(10, 0);
const buf2 = Buffer.alloc(14, 0);
const buf3 = Buffer.alloc(18, 0);
const totalLength = buf1.length + buf2.length + buf3.length;
console.log(totalLength);
const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);
console.log(bufA);
console.log(bufA.length);
// 42
// <Buffer 00 00 00 00 ... >
// 42