method

quic.QuicStream.setBody

): void;

Sets the outbound body source for the stream. Can only be called once. Mutually exclusive with stream.writer.

The following body source types are supported:

  • null — The writable side is closed immediately (FIN sent with no data).
  • string — UTF-8 encoded and sent as a single chunk.
  • ArrayBuffer, SharedArrayBuffer, ArrayBufferView — Sent as a single chunk. The bytes are copied into an internal buffer, so the caller's source buffer is unchanged and may be reused or mutated immediately after the call returns. Callers wanting to ensure their source cannot be mutated after handing it off can call ArrayBuffer.prototype.transfer() themselves before passing the buffer.
  • Blob — Sent from the Blob's underlying data queue.
  • {FileHandle} — The file contents are read asynchronously via an fd-backed data source. The FileHandle must be opened for reading (e.g. via [fs.promises.open(path, 'r')][]). Once passed as a body, the FileHandle is locked and cannot be used as a body for another stream. The FileHandle is automatically closed when the stream finishes.
  • AsyncIterable, Iterable — Each yielded chunk (string or Uint8Array) is written incrementally in streaming mode.
  • Promise — Awaited; the resolved value is used as the body (subject to the same type rules).

Throws ERR_INVALID_STATE if the outbound is already configured or if the writer has been accessed.

Referenced types

type StreamBody =
| null
| string
| ArrayBufferLike
| NodeJS.ArrayBufferView
| Iterable<string | Uint8Array>
| AsyncIterable<string | Uint8Array>
| Promise<StreamBody>