MCPcopy Index your code
hub / github.com/nodejs/node / chunksConcat

Function chunksConcat

deps/undici/src/lib/api/readable.js:496–514  ·  view source on GitHub ↗

* @param {Buffer[]} chunks * @param {number} length * @returns {Uint8Array}

(chunks, length)

Source from the content-addressed store, hash-verified

494 * @returns {Uint8Array}
495 */
496function chunksConcat (chunks, length) {
497 if (chunks.length === 0 || length === 0) {
498 return new Uint8Array(0)
499 }
500 if (chunks.length === 1) {
501 // fast-path
502 return new Uint8Array(chunks[0])
503 }
504 const buffer = new Uint8Array(Buffer.allocUnsafeSlow(length).buffer)
505
506 let offset = 0
507 for (let i = 0; i < chunks.length; ++i) {
508 const chunk = chunks[i]
509 buffer.set(chunk, offset)
510 offset += chunk.length
511 }
512
513 return buffer
514}
515
516/**
517 * @param {Consume} consume

Callers 1

consumeEndFunction · 0.70

Calls 1

setMethod · 0.45

Tested by

no test coverage detected