Skip to content

BodyReader

Defined in: packages/format-core/src/body-reader.ts:28

Turns a declared BodySpec into a ReadableStream, fed byte-by-byte (or chunk-by-chunk) as they arrive alongside or after a decoded value.

Extracted from net/core’s Framer (now FrameLink) so the same deferred-materialization mechanics — an opaque payload declared by a decoder and streamed rather than buffered — are available to any consumer, not just a live transport. First consumer: FrameLink; a RIFF/WAV reader or an IMAP literal retrofit are the next two, per format-interface-dimensions.md.

Cancelling stream does not stop the body: its remaining bytes are still consumed by feed, and dropped, so whatever follows the body on the same carrier stays in sync.

new BodyReader(spec, options): BodyReader

Defined in: packages/format-core/src/body-reader.ts:38

BodySpec

BodyReaderOptions

BodyReader

readonly stream: ReadableStream<Uint8Array<ArrayBufferLike>>

Defined in: packages/format-core/src/body-reader.ts:36

The stream to hand to whoever is consuming the body.

get finished(): boolean

Defined in: packages/format-core/src/body-reader.ts:65

Whether every byte of the body has been fed, or the body was discarded.

boolean

discard(error?): void

Defined in: packages/format-core/src/body-reader.ts:128

Errors the stream, for a transport failure or a mode switch mid-body. Idempotent: a second call is a no-op.

Leaves backpressure as it is: whoever discards decides what happens to the carrier next.

unknown

void


feed(chunk): number

Defined in: packages/format-core/src/body-reader.ts:74

Push up to remaining bytes of chunk into the stream.

Uint8Array

number

How many bytes of chunk were consumed by the body.


finish(): void

Defined in: packages/format-core/src/body-reader.ts:110

Closes the stream normally. Idempotent: a second call is a no-op.

Lifts any backpressure this reader applied: the bytes after the body are no longer its to hold back, and a closed stream is never pulled again.

void


finishAtEof(): void

Defined in: packages/format-core/src/body-reader.ts:98

Signals end-of-input for an until-eof body; a no-op for a length one.

void