* @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)
| 938 | * @see https://fetch.spec.whatwg.org/#body-fully-read |
| 939 | */ |
| 940 | function 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 |
no test coverage detected