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
Custom protocol
API
XStreamOptions
| Prop | Description | Type | Default | Version |
|---|---|---|---|---|
| readableStream | Binary readable stream | ReadableStream<Uint8Array> | - | - |
| transformStream | Custom TransformStream; if not passed, the default SSE transform is used | TransformStream<string, T> | sseTransformStream | - |
| streamSeparator | Stream event separator; ignored when transformStream is set | string | \n\n | 2.2.0 |
| partSeparator | Field separator inside one event; ignored when transformStream is set | string | \n | 2.2.0 |
| kvSeparator | Separator between field names and values; ignored when transformStream is set | string | : | 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.