Reference / @open-music-sdk/core / readBounded
Function: readBounded()
function readBounded(message, maxBytes): Promise<string | undefined>;Defined in: packages/core/src/body.ts:16
The body of a request or a response as text, or undefined once it has run past maxBytes. It is counted as it arrives, after any decompression, and what lies beyond the limit is cancelled rather than read: whoever sends a body decides how much is sent, and must not decide how much is kept. A body that cannot be read, since it was read already or the connection dropped, rejects with the runtime's own error, as it is.
Parameters
message
Request | Response
The request or response whose body to read.
maxBytes
number
The most bytes to keep, a whole number from 0.
Returns
Promise<string | undefined>
The whole body as text, or undefined when it ran past maxBytes or a Content-Length header said it would.
Throws
TypeError if maxBytes is not a whole number from 0.
Throws
Whatever the runtime rejects with when the body cannot be read, as it is.