Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Stream documentation #17506

Open
wants to merge 1 commit into
base: production
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/content/docs/workers/runtime-apis/streams/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The [Streams API](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API)

<DirectoryListing />

Workers do not need to prepare an entire response body before delivering it to `event.respondWith()`. You can use [`TransformStream`](/workers/runtime-apis/streams/transformstream/) to stream a response body after sending the front matter (that is, HTTP status line and headers). This allows you to minimize:
Workers do not need to prepare an entire response body before returning a `Response`. You can use a [`ReadableStream`](/workers/runtime-apis/streams/readablestream/) to stream a response body after sending the front matter (that is, HTTP status line and headers). This allows you to minimize:

* The visitor’s time-to-first-byte.
* The buffering done in the Worker.
Expand All @@ -39,7 +39,7 @@ The worker can create a `Response` object using a `ReadableStream` as the body.
export default {
async fetch(request, env, ctx) {
// Fetch from origin server.
let response = await fetch(request);
const response = await fetch(request);

// ... and deliver our Response while that’s running.
return new Response(response.body, response);
Expand All @@ -56,7 +56,7 @@ addEventListener('fetch', event => {

async function fetchAndStream(request) {
// Fetch from origin server.
let response = await fetch(request);
const response = await fetch(request);

// ... and deliver our Response while that’s running.
return new Response(readable.body, response);
Expand All @@ -73,9 +73,9 @@ A [`TransformStream`](/workers/runtime-apis/streams/transformstream/) and the [`
export default {
async fetch(request, env, ctx) {
// Fetch from origin server.
let response = await fetch(request);
const response = await fetch(request);

let { readable, writable } = new TransformStream({
const { readable, writable } = new TransformStream({
transform(chunk, controller) {
controller.enqueue(modifyChunkSomehow(chunk));
}
Expand All @@ -99,9 +99,9 @@ addEventListener('fetch', event => {

async function fetchAndStream(request) {
// Fetch from origin server.
let response = await fetch(request);
const response = await fetch(request);

let { readable, writable } = new TransformStream({
const { readable, writable } = new TransformStream({
transform(chunk, controller) {
controller.enqueue(modifyChunkSomehow(chunk));
}
Expand Down
Loading