Skip to content

Commit

Permalink
Update ReadableStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick-ring-motive authored Oct 8, 2024
1 parent 9a3940b commit 5a62473
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 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,32 @@ 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
}
```
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")}}
- `string` literal
## Specifications

{{Specifications}}
Expand Down

0 comments on commit 5a62473

Please sign in to comment.