MCPcopy Create free account
hub / github.com/nodejs/node / fullyReadBody

Function fullyReadBody

deps/undici/src/lib/web/fetch/util.js:940–963  ·  view source on GitHub ↗

* @param {import('./body').ExtractBodyResult} body * @param {(bytes: Uint8Array) => void} processBody * @param {(error: Error) => void} processBodyError * @returns {void} * * @see https://fetch.spec.whatwg.org/#body-fully-read

(body, processBody, processBodyError)

Source from the content-addressed store, hash-verified

938 * @see https://fetch.spec.whatwg.org/#body-fully-read
939 */
940function fullyReadBody (body, processBody, processBodyError) {
941 // 1. If taskDestination is null, then set taskDestination to
942 // the result of starting a new parallel queue.
943
944 // 2. Let successSteps given a byte sequence bytes be to queue a
945 // fetch task to run processBody given bytes, with taskDestination.
946 const successSteps = processBody
947
948 // 3. Let errorSteps be to queue a fetch task to run processBodyError,
949 // with taskDestination.
950 const errorSteps = processBodyError
951
952 try {
953 // 4. Let reader be the result of getting a reader for body’s stream.
954 // If that threw an exception, then run errorSteps with that
955 // exception and return.
956 const reader = body.stream.getReader()
957
958 // 5. Read all bytes from reader, given successSteps and errorSteps.
959 readAllBytes(reader, successSteps, errorSteps)
960 } catch (e) {
961 errorSteps(e)
962 }
963}
964
965/**
966 * @param {ReadableStreamController<Uint8Array>} controller

Callers 2

mainFetchFunction · 0.70
consumeBodyFunction · 0.70

Calls 2

getReaderMethod · 0.80
readAllBytesFunction · 0.70

Tested by

no test coverage detected