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 ReadableStream #36270

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 5 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
19 changes: 19 additions & 0 deletions files/en-us/web/api/readablestream/readablestream/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ const stream = new ReadableStream({
});
```

A useful way to construct a `ReadableStream` from a variety of input types is to use the body property of a {{domxref("Response.Response","Response")}} object

```js
function newReadableStream(content) {
return new Response(content).body;
}

const newStream = newReadableStream("Hello World");

const decoder = new TextDecoder();

for await (const chunk of newStream) {
console.log(decoder.decode(chunk)); //Hello World
}
```


Patrick-ring-motive marked this conversation as resolved.
Show resolved Hide resolved
An object defining a body for the response can be `null` (which is the default value), or one of {{domxref("Blob")}}, {{jsxref("ArrayBuffer")}}, {{jsxref("TypedArray")}}, {{jsxref("DataView")}}, {{domxref("FormData")}}, {{domxref("ReadableStream")}}, {{domxref("URLSearchParams")}}, {{jsxref("String")}}, or `string` literal.

## Specifications

{{Specifications}}
Expand Down
Loading