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

Function chunksDecode

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

* @param {Buffer[]} chunks * @param {number} length * @param {BufferEncoding} [encoding='utf8'] * @returns {string}

(chunks, length, encoding)

Source from the content-addressed store, hash-verified

467 * @returns {string}
468 */
469function chunksDecode (chunks, length, encoding) {
470 if (chunks.length === 0 || length === 0) {
471 return ''
472 }
473 const buffer = chunks.length === 1 ? chunks[0] : Buffer.concat(chunks, length)
474 const bufferLength = buffer.length
475
476 // Skip BOM.
477 const start =
478 bufferLength > 2 &&
479 buffer[0] === 0xef &&
480 buffer[1] === 0xbb &&
481 buffer[2] === 0xbf
482 ? 3
483 : 0
484 if (!encoding || encoding === 'utf8' || encoding === 'utf-8') {
485 return buffer.utf8Slice(start, bufferLength)
486 } else {
487 return buffer.subarray(start, bufferLength).toString(encoding)
488 }
489}
490
491/**
492 * @param {Buffer[]} chunks

Callers 1

consumeEndFunction · 0.70

Calls 3

concatMethod · 0.80
utf8SliceMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected