2.10.0
中文
Skip to content

XStream ​

Collect ReadableStream\<Uint8Array> into asynchronously iterable records. If transformStream is not passed, split according to SSE: events are separated by blank lines and : separates field names and values; all three separators are configurable. Leaving the async loop early cancels the underlying stream and releases the reader lock.

ts
import { XStream } from 'ant-design-x-vue';

for await (const chunk of XStream({ readableStream })) {
  console.log(chunk);
}

If readableStream is not a ReadableStream, throw The options.readableStream must be an instance of ReadableStream.

Default protocol — SSE ​

Default protocol — SSE

Assemble Hello, world! from in-memory SSE chunks with no network request.

Custom protocol ​

Custom protocol

Pass transformStream to read in chunks according to a custom protocol (SIP/SDP text).

API ​

XStreamOptions ​

PropDescriptionTypeDefaultVersion
readableStreamBinary readable streamReadableStream<Uint8Array>--
transformStreamCustom TransformStream; if not passed, the default SSE transform is usedTransformStream<string, T>sseTransformStream-
streamSeparatorStream event separator; ignored when transformStream is setstring\n\n2.2.0
partSeparatorField separator inside one event; ignored when transformStream is setstring\n2.2.0
kvSeparatorSeparator between field names and values; ignored when transformStream is setstring:2.2.0
ts
type SSEFields = 'data' | 'event' | 'id' | 'retry';
type SSEOutput = Partial<Record<SSEFields, any>>;

type XReadableStream<R = SSEOutput> = ReadableStream<R> & AsyncGenerator<R>;

function XStream<Output = SSEOutput>(
  options: XStreamOptions<Output>,
): XReadableStream<Output>;

The 1.x page is still at XStream Stream. The usage in 2.x is the same, implemented from @ant-design-x-vue/x-sdk.