logoAnt Design X

DesignDevelopmentComponentsPlayground
  • Overview
  • Common
    • Bubble
    • Conversations
  • Wake
    • Welcome
    • Prompts
  • Express
    • Attachments
    • Sender
    • Suggestion
  • Confirm
    • ThoughtChain
  • Tools
    • useXAgent
    • useXChat
    • XStream
    • XRequest
    • XProvider

XStream

Transform binary stream
Importimport { XStream } from "@ant-design/x";
Sourcecomponents/x-stream
Docs
Edit this pageChangelog

Resources

Ant Design
Ant Design Charts
Ant Design Pro
Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Web3
Ant Design Landing-Landing Templates
Scaffolds-Scaffold Market
Umi-React Application Framework
dumi-Component doc generator
qiankun-Micro-Frontends Framework
Ant Motion-Motion Solution
China Mirror 🇨🇳

Community

Awesome Ant Design
Medium
Twitter
yuque logoAnt Design in YuQue
Ant Design in Zhihu
Experience Cloud Blog
seeconf logoSEE Conf-Experience Tech Conference

Help

GitHub
Change Log
FAQ
Bug Report
Issues
Discussions
StackOverflow
SegmentFault

Ant XTech logoMore Products

yuque logoYuQue-Document Collaboration Platform
AntV logoAntV-Data Visualization
Egg logoEgg-Enterprise Node.js Framework
Kitchen logoKitchen-Sketch Toolkit
Galacean logoGalacean-Interactive Graphics Solution
xtech logoAnt Financial Experience Tech
Theme Editor
Made with ❤ by
Ant Group and Ant Design Community
loading

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:

js
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

API

XStreamOptions

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

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

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom Protocol

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.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code