logoAnt Design X

XStream

Transform binary stream
Import
import{ XStream }from"@ant-design/x";

When To Use

  • Transform SSE protocol ReadableStream to Record
  • Decode and read any protocol ReadableStream

Use

Common ReadableStream instances, such as await fetch(...).body, usage example:

import { XStream } from '@ant-design/x';
async function request() {
const response = await fetch();
// .....
for await (const chunk of XStream({
readableStream: response.body,
})) {
console.log(chunk);
}
}

Examples

SSE - https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events

The default transformStream in XStream is an SSE protocol stream transformer and is optional. The readableStream accepts a new ReadableStream(...) instance, such as await fetch(...).body

codepen icon
External Link Icon
expand codeexpand code

In this example, we will demonstrate parsing the SIP protocol, which is commonly used for P2P audio and video session initiation.

Pass in a transformStream stream transformer; this parameter accepts a new TransformStream(...) instance.

codepen icon
External Link Icon
expand codeexpand code

API

XStreamOptions

PropertyDescriptionTypeDefaultVersion
readableStreamReadable stream of binary dataReadableStream<'Uint8Array'>--
transformStreamSupport customizable transformStream to transform streamsTransformStream<string, T>sseTransformStream-
Ask me