Skip to content

Latest commit

 

History

History
18 lines (13 loc) · 484 Bytes

bufferconcat.md

File metadata and controls

18 lines (13 loc) · 484 Bytes

Buffer.concat

Buffer.concat accepts the total byte length of all the Buffers in the array as a second argument to prevent a primary pass over the array:

const buffers: Buffer[] = [];
let byteLength = 0;

for await (const chunk of res as IncomingMessage) {
  buffers.push(chunk);
  byteLength += chunk.byteLength;
}

const result = Buffer.concat(buffers, byteLength);

source