-
Notifications
You must be signed in to change notification settings - Fork 23.3k
Expand file tree
/
Copy pathindex.md
More file actions
54 lines (41 loc) · 1.31 KB
/
Copy pathindex.md
File metadata and controls
54 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
title: "TransformStream: readable property"
short-title: readable
slug: Web/API/TransformStream/readable
page-type: web-api-instance-property
browser-compat: api.TransformStream.readable
---
{{APIRef("Streams")}}{{AvailableInWorkers}}
The **`readable`** read-only property of the {{domxref("TransformStream")}} interface returns the {{domxref("ReadableStream")}} instance controlled by this `TransformStream`. This stream emits the transformed output data.
## Value
A {{domxref("ReadableStream")}}.
## Examples
This example creates a `TransformStream` that converts all input text to uppercase letters. It writes some text to the `writable` stream, then reads the transformed text from the `readable` stream.
```js
const stream = new TransformStream({
transform(chunk, controller) {
controller.enqueue(chunk.toUpperCase());
},
});
// Write data to be transformed
const writer = stream.writable.getWriter();
writer.write("hello ");
writer.write("world");
writer.close();
// Read transformed data
const reader = stream.readable.getReader();
let done = false;
let output = "";
while (!done) {
const result = await reader.read();
if (result.value) {
output += result.value;
}
done = result.done;
}
console.log(output); // HELLO WORLD
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}