Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2cc1ffa

Browse files
committed
Expand Stream docs
1 parent c20e0ef commit 2cc1ffa

29 files changed

+973
-66
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
QueuingStrategy : Object
2+
3+
Spec:
4+
https://streams.spec.whatwg.org/#qs
5+
6+
7+
----
8+
instance.highWaterMark : Number
9+
10+
Spec:
11+
https://streams.spec.whatwg.org/#dom-queuingstrategy-highwatermark
12+
13+
----
14+
instance.size(chunk : Object) : Number
15+
16+
Spec:
17+
https://streams.spec.whatwg.org/#dom-queuingstrategy-size
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ReadableStreamByteController : ReadableStreamController
2+
3+
Spec:
4+
https://streams.spec.whatwg.org/#readablebytestreamcontroller
5+
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ReadableStreamController : Object
2+
3+
4+
5+
Spec:
6+
https://streams.spec.whatwg.org/#typedefdef-readablestreamcontroller

content/Streams/ReadableStreamDefaultController.jsdoc

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
ReadableStreamDefaultController : Object
1+
ReadableStreamDefaultController : ReadableStreamController
2+
3+
Controls a %%/ReadableStream|ReadableStream's%% state and queue.
24

35
Spec:
46
https://streams.spec.whatwg.org/#readablestreamdefaultcontroller
@@ -12,10 +14,50 @@ true
1214
----
1315
prototype.close() : undefined
1416

17+
Causes the owning stream to close.
18+
19+
<example>
20+
// Create a stream of strings.
21+
const stringStream = new ReadableStream({
22+
start(controller) {
23+
controller.enqueue('a');
24+
controller.enqueue('b');
25+
controller.close();
26+
}
27+
});
28+
29+
const reader = stringStream.getReader();
30+
let result;
31+
while (!(result = await reader.read()).done) {
32+
console.log(result.value);
33+
}
34+
console.log('done');
35+
</example>
1536

1637
----
17-
prototype.enqueue([chunk : Object]) : undefined
38+
prototype.enqueue(chunk : Object) : undefined
39+
40+
Causes the owning stream to return **chunk**.
41+
42+
<example>
43+
// Create a stream of strings.
44+
const stringStream = new ReadableStream({
45+
start(controller) {
46+
['a', 'b', 'c'].forEach(s => controller.enqueue(s));
47+
controller.close();
48+
}
49+
});
50+
51+
const reader = stringStream.getReader();
52+
let result;
53+
while (!(result = await reader.read()).done) {
54+
console.log(result.value);
55+
}
56+
</example>
57+
58+
Spec:
59+
https://streams.spec.whatwg.org/#rs-default-controller-enqueue
1860

1961
----
20-
prototype.error([e : Object]) : undefined
62+
prototype.error(reason : Object) : undefined
2163

content/Streams/ReadableStreamDefaultReader.jsdoc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,57 @@ new ReadableStreamDefaultReader(stream : ReadableStream) : ReadableStreamDefault
99
----
1010
instance.closed : Promise<undefined>
1111

12+
A promise that resolves when the stream closes.
13+
14+
<example>
15+
const stringStream = new ReadableStream({
16+
start(controller) {
17+
controller.enqueue('a');
18+
controller.enqueue('b');
19+
controller.close();
20+
}
21+
});
22+
23+
const reader = stringStream.getReader();
24+
reader.closed.then(() => console.log('reader closed'));
25+
26+
let result;
27+
while (!(result = await reader.read()).done) {
28+
console.log(result.value);
29+
}
30+
console.log('done');
31+
</example>
32+
1233
ReadOnly:
1334
true
1435

1536
----
1637
prototype.cancel([reason : Object]) : Promise<undefined>
1738

39+
Causes the stream to cancel and stop producing new chunks. Causes the
40+
UnderlyingSource's %%/UnderlyingSource#cancel|cancel%% method to be called.
41+
42+
<example>
43+
const stringStream = new ReadableStream({
44+
start(controller) {
45+
controller.enqueue('a');
46+
controller.enqueue('b');
47+
controller.close();
48+
},
49+
cancel(reason) {
50+
console.log(`cancel reason: ${reason}`);
51+
}
52+
});
53+
54+
const reader = stringStream.getReader();
55+
56+
let result;
57+
while (!(result = await reader.read()).done) {
58+
console.log(result.value);
59+
reader.cancel('xyz');
60+
}
61+
</example>
62+
1863
----
1964
prototype.read() : Promise
2065

@@ -23,3 +68,24 @@ Promise return type:
2368

2469
----
2570
prototype.releaseLock() : undefined;
71+
72+
Release the lock on the ReadableStream so another reader can read from the stream.
73+
74+
<example>
75+
const stringStream = new ReadableStream({
76+
start(controller) {
77+
controller.enqueue('a');
78+
controller.enqueue('b');
79+
controller.close();
80+
}
81+
});
82+
83+
const reader1 = stringStream.getReader();
84+
const result1 = await reader1.read();
85+
console.log(result1.value);
86+
reader1.releaseLock();
87+
88+
const reader2 = new ReadableStreamDefaultReader(stringStream);
89+
const result2 = await reader2.read();
90+
console.log(result2.value);
91+
</example>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
ReadableStreamSource : Object
2+
3+
Object that provides the sequence of values for a %%/ReadableStream|ReadableStream%%.
4+
Passed to the %%/ReadableStream|ReadableStream%% constructor. Any JavaScript object
5+
can be used as a readable stream source. Any of the properties/method can be specified.
6+
If a property/method is not provided, the ReadableStream will use a default behavior
7+
for the property/method.
8+
9+
Spec:
10+
https://streams.spec.whatwg.org/#dictdef-underlyingsource
11+
12+
----
13+
instance.start(controller : ReadableStreamController) : Object
14+
15+
<example>
16+
// Create a stream of strings.
17+
const stringStream = new ReadableStream({
18+
start(controller) {
19+
['a', 'b', 'c'].forEach(s => controller.enqueue(s));
20+
}
21+
});
22+
23+
const reader = stringStream.getReader();
24+
let result;
25+
while (!(result = await reader.read()).done) {
26+
console.log(result.value);
27+
}
28+
</example>
29+
30+
Spec:
31+
https://streams.spec.whatwg.org/#dom-underlyingsource-start
32+
33+
----
34+
instance.pull(controller : ReadableStreamController) : Promise<undefined>
35+
36+
Called each time the stream's internal queue drops below the
37+
%%/QueuingStrategy#highWaterMark|high water mark%%, indicating **this** should
38+
enqueue more chunks.
39+
40+
<example>
41+
const stringStream = new ReadableStream({
42+
i: 1,
43+
pull(controller) {
44+
console.log('pull', controller.desiredSize);
45+
while (controller.desiredSize > 0) {
46+
controller.enqueue(`chunk_${this.i++}`);
47+
}
48+
if (this.i > 5) controller.close();
49+
}
50+
}, new CountQueuingStrategy({ highWaterMark: 2 }));
51+
52+
const reader = stringStream.getReader();
53+
let result;
54+
while (!(result = await reader.read()).done) {
55+
console.log('received:', result.value);
56+
}
57+
</example>
58+
59+
Spec:
60+
https://streams.spec.whatwg.org/#dom-underlyingsource-pull
61+
62+
----
63+
instance.cancel(reason : Object) : Promise<undefined>
64+
65+
Called when the stream has been canceled, either by %%/ReadableStream#cancel|ReadableStream.cancel()%% or
66+
%%ReadableStreamDefaultReader#cancel|Reader.cancel()%%, with **reason** as the value
67+
passed to that function.
68+
69+
<example>
70+
const stringStream = new ReadableStream({
71+
start(controller) {
72+
controller.enqueue('a');
73+
controller.enqueue('b');
74+
controller.close();
75+
},
76+
cancel(reason) {
77+
console.log(`cancel reason: ${reason}`);
78+
}
79+
});
80+
81+
const reader = stringStream.getReader();
82+
83+
let result;
84+
while (!(result = await reader.read()).done) {
85+
console.log(result.value);
86+
reader.cancel('xyz');
87+
}
88+
</example>
89+
90+
Spec:
91+
https://streams.spec.whatwg.org/#dom-underlyingsource-pull
92+
93+
----
94+
instance.type : String
95+
96+
If set to **'bytes'**, the ReadableStream will be a readable byte stream.
97+
98+
Spec:
99+
https://streams.spec.whatwg.org/#dom-underlyingsource-type
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
TransformStream : Object
2+
3+
Spec:
4+
https://streams.spec.whatwg.org/#ts-class
5+
6+
----
7+
new TransformStream([transformer: Transformer, [writableStrategy: QueuingStrategy, [readableStrategy: QueuingStrategy]]]) : TransformStream
8+
9+
<example>
10+
const reader = new ReadableStream({
11+
start(controller) {
12+
['a', 'b', 'c'].forEach(s => controller.enqueue(s));
13+
controller.close();
14+
}
15+
}).pipeThrough(new TransformStream({
16+
transform(chunk, controller) {
17+
controller.enqueue(chunk.toUpperCase());
18+
}
19+
})).getReader();
20+
21+
let result;
22+
while (!(result = await reader.read()).done) {
23+
console.log(result.value);
24+
}
25+
</example>
26+
27+
----
28+
instance.readable : ReadableStream
29+
30+
ReadOnly:
31+
true
32+
33+
----
34+
instance.writable : ReadableStream
35+
36+
ReadOnly:
37+
true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
TransformStreamDefaultController : Object
2+
3+
4+
Spec:
5+
https://streams.spec.whatwg.org/#ts-default-controller-class
6+
7+
----
8+
instance.desiredSize : Number
9+
10+
ReadOnly:
11+
true
12+
13+
Spec:
14+
https://streams.spec.whatwg.org/#ts-default-controller-desired-size
15+
16+
----
17+
prototype.enqueue(chunk : Object) : undefined
18+
19+
Spec:
20+
https://streams.spec.whatwg.org/#ts-default-controller-enqueue
21+
22+
----
23+
prototype.error(reason : Object) : undefined
24+
25+
Spec:
26+
https://streams.spec.whatwg.org/#ts-default-controller-error
27+
28+
----
29+
prototype.terminate() : undefined
30+
31+
Spec:
32+
https://streams.spec.whatwg.org/#ts-default-controller-terminate

0 commit comments

Comments
 (0)