---
title: "Stream"
description: "This page lists the TypeScript SDK names for Streams."
canonical_url: "https://docs.superdurable.io/zh-Hans/reference/typescript/stream/"
source: "docs/reference/typescript/stream.mdx"
locale: "zh-Hans"
---

# Stream

This page lists the TypeScript SDK names for [Streams](https://docs.superdurable.io/zh-Hans/concepts/primitives/stream.md).
The doc comment of each API gives its parameters, defaults, and errors. Read
them in the [TypeScript SDK API reference](https://docs.superdurable.io/zh-Hans/reference/typescript.md#api-reference).

<a id="api-names"></a>

## API names

| Task                                     | TypeScript API                                                                  | Dex behavior                                                                                                     |
| ---------------------------------------- | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| Define a Stream and its byte capacity    | **Stream**, with **streamCapacityBytes**                                        | [Capacity and trimming](https://docs.superdurable.io/zh-Hans/reference/server/runtime-data.md#stream-capacity)   |
| Declare it in the Flow                   | **streams** of the **PersistenceSchema** returned from **getPersistenceSchema** | [Flow definition](https://docs.superdurable.io/zh-Hans/reference/typescript/flow.md#flow-definition)             |
| Write a message from a Step              | **Stream.write**                                                                | [Write semantics](https://docs.superdurable.io/zh-Hans/reference/server/runtime-data.md#stream-write-semantics)  |
| Write text chunks in batches from a Step | **Stream.bufferedText**                                                         | [Buffer text chunks](https://docs.superdurable.io/zh-Hans/reference/server/runtime-data.md#stream-buffered-text) |
| Write a message from a Client            | **Client.writeStream**                                                          | [Write semantics](https://docs.superdurable.io/zh-Hans/reference/server/runtime-data.md#stream-write-semantics)  |
| Read the next message                    | **Client.readStream**, with the **resumeToken** of the last message             | [Resumable reads](https://docs.superdurable.io/zh-Hans/reference/server/runtime-data.md#stream-resumable-reads)  |
| List retained messages, newest first     | **Client.listStreamMessages**                                                   | [List messages](https://docs.superdurable.io/zh-Hans/reference/server/runtime-data.md#stream-listing)            |

**Stream.write** works in **waitFor**, **execute**, and the Flow timeout
handler. An RPC handler cannot write a Stream. **Stream.write** sends the
message immediately and returns nothing. Use **Stream.bufferedText** in an
asynchronous Step.

<a id="example"></a>

## Example

Example: [examples/typescript/src/primitives/stream/stream-flow.ts](https://github.com/superdurable/dex/tree/main/examples/typescript/src/primitives/stream/stream-flow.ts)
