0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-29 17:46:30 +01:00
hono/deno_dist/helper/streaming/index.ts
Sor4chi 7768865e7a
fix: move c.stream* to helper (#1846)
* refactor: move streaming helper to `streaming/sse.ts`

* feat: add streamSSE's export in streaming handler

* feat: move `stream` and `streamText` to streaming helper

* chore: add deprecated expression for `c.stream` and `c.streamText`

* fix: use `stream` helper in streamSSE

* refactor: move `streamText` to `text.ts`

* test: add some case to `stream` and `streamText`

* test: refactor `streamSSE` case for uniformity

* chore: denoify

* fix: update jsdoc's deprecated description, simplify `c.stream` and `c.streamText`

* fix: match the header notation with that of `streamSSE

* chore: denoify

* refactor: remove unnecesary export
2023-12-27 06:55:24 +09:00

13 lines
451 B
TypeScript

import type { Context } from '../../context.ts'
import { StreamingApi } from '../../utils/stream.ts'
export const stream = (c: Context, cb: (stream: StreamingApi) => Promise<void>): Response => {
const { readable, writable } = new TransformStream()
const stream = new StreamingApi(writable)
cb(stream).finally(() => stream.close())
return c.newResponse(readable)
}
export { streamSSE } from './sse.ts'
export { streamText } from './text.ts'