MCPcopy Create free account
hub / github.com/nodejs/undici / chunksDecode

Function chunksDecode

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

490 * @returns {string}
491 */
492function chunksDecode (chunks, length, encoding) {
493 if (chunks.length === 0 || length === 0) {
494 return ''
495 }
496 const buffer = chunks.length === 1 ? chunks[0] : Buffer.concat(chunks, length)
497 const bufferLength = buffer.length
498
499 // Skip BOM.
500 const start =
501 bufferLength > 2 &&
502 buffer[0] === 0xef &&
503 buffer[1] === 0xbb &&
504 buffer[2] === 0xbf
505 ? 3
506 : 0
507 if (!encoding || encoding === 'utf8' || encoding === 'utf-8') {
508 return buffer.utf8Slice(start, bufferLength)
509 } else {
510 return buffer.subarray(start, bufferLength).toString(encoding)
511 }
512}
513
514/**
515 * @param {Buffer[]} chunks

Callers 1

consumeEndFunction · 0.85

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected