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

Function chunksDecode

lib/api/readable.js:510–530  ·  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

508 * @returns {string}
509 */
510function chunksDecode (chunks, length, encoding) {
511 if (chunks.length === 0 || length === 0) {
512 return ''
513 }
514 const buffer = chunks.length === 1 ? chunks[0] : Buffer.concat(chunks, length)
515 const bufferLength = buffer.length
516
517 // Skip BOM.
518 const start =
519 bufferLength > 2 &&
520 buffer[0] === 0xef &&
521 buffer[1] === 0xbb &&
522 buffer[2] === 0xbf
523 ? 3
524 : 0
525 if (!encoding || encoding === 'utf8' || encoding === 'utf-8') {
526 return buffer.utf8Slice(start, bufferLength)
527 } else {
528 return buffer.subarray(start, bufferLength).toString(encoding)
529 }
530}
531
532/**
533 * @param {Buffer[]} chunks

Callers 1

consumeEndFunction · 0.85

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…