File tree Expand file tree Collapse file tree 7 files changed +107
-4
lines changed Expand file tree Collapse file tree 7 files changed +107
-4
lines changed Original file line number Diff line number Diff line change @@ -2154,6 +2154,57 @@ added: v16.8.0
2154
2154
2155
2155
Returns whether the stream has been read from or cancelled.
2156
2156
2157
+ ### ` stream.isErrored(stream) `
2158
+
2159
+ <!-- YAML
2160
+ added: REPLACEME
2161
+ -->
2162
+
2163
+ > Stability: 1 - Experimental
2164
+
2165
+ * ` stream ` {Readable|Writable|Duplex|WritableStream|ReadableStream}
2166
+ * Returns: {boolean}
2167
+
2168
+ Returns whether the stream has encountered an error.
2169
+
2170
+ ### ` stream.Readable.toWeb(streamReadable) `
2171
+
2172
+ <!-- YAML
2173
+ added: v17.0.0
2174
+ -->
2175
+
2176
+ > Stability: 1 - Experimental
2177
+
2178
+ * ` streamReadable ` {stream.Readable}
2179
+ * Returns: {ReadableStream}
2180
+
2181
+ ### ` stream.Writable.fromWeb(writableStream[, options]) `
2182
+
2183
+ <!-- YAML
2184
+ added: v17.0.0
2185
+ -->
2186
+
2187
+ > Stability: 1 - Experimental
2188
+
2189
+ * ` writableStream ` {WritableStream}
2190
+ * ` options ` {Object}
2191
+ * ` decodeStrings ` {boolean}
2192
+ * ` highWaterMark ` {number}
2193
+ * ` objectMode ` {boolean}
2194
+ * ` signal ` {AbortSignal}
2195
+ * Returns: {stream.Writable}
2196
+
2197
+ ### ` stream.Writable.toWeb(streamWritable) `
2198
+
2199
+ <!-- YAML
2200
+ added: v17.0.0
2201
+ -->
2202
+
2203
+ > Stability: 1 - Experimental
2204
+
2205
+ * ` streamWritable ` {stream.Writable}
2206
+ * Returns: {WritableStream}
2207
+
2157
2208
### ` stream.Duplex.from(src) `
2158
2209
2159
2210
<!-- YAML
Original file line number Diff line number Diff line change 6
6
SymbolIterator,
7
7
} = primordials ;
8
8
9
+ const kDestroyed = Symbol ( 'kDestroyed' ) ;
10
+ const kIsErrored = Symbol ( 'kIsErrored' ) ;
9
11
const kIsDisturbed = Symbol ( 'kIsDisturbed' ) ;
10
12
11
13
function isReadableNodeStream ( obj ) {
@@ -212,10 +214,30 @@ function willEmitClose(stream) {
212
214
) ;
213
215
}
214
216
217
+ function isDisturbed ( stream ) {
218
+ return ! ! ( stream && (
219
+ stream [ kIsDisturbed ] ??
220
+ ( stream . readableDidRead || stream . readableAborted )
221
+ ) ) ;
222
+ }
223
+
224
+ function isErrored ( stream ) {
225
+ return ! ! ( stream && (
226
+ stream [ kIsErrored ] ??
227
+ stream . readableErrored ??
228
+ stream . writableErrored ??
229
+ stream . _readableState ?. errorEmitted ??
230
+ stream . _writableState ?. errorEmitted ??
231
+ stream . _readableState ?. errored ??
232
+ stream . _writableState ?. errored
233
+ ) ) ;
234
+ }
215
235
216
236
module . exports = {
217
237
isDisturbed,
238
+ isErrored,
218
239
kIsDisturbed,
240
+ kIsErrored,
219
241
isClosed,
220
242
isDestroyed,
221
243
isDuplexNodeStream,
Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ const {
82
82
83
83
const {
84
84
kIsDisturbed,
85
+ kIsErrored,
85
86
} = require ( 'internal/streams/utils' ) ;
86
87
87
88
const {
@@ -241,6 +242,10 @@ class ReadableStream {
241
242
return this [ kState ] . disturbed ;
242
243
}
243
244
245
+ get [ kIsErrored ] ( ) {
246
+ return this [ kState ] . state === 'errored' ;
247
+ }
248
+
244
249
/**
245
250
* @readonly
246
251
* @type {boolean }
Original file line number Diff line number Diff line change @@ -36,9 +36,11 @@ const eos = require('internal/streams/end-of-stream');
36
36
const internalBuffer = require ( 'internal/buffer' ) ;
37
37
38
38
const promises = require ( 'stream/promises' ) ;
39
+ const utils = require ( 'internal/streams/utils' ) ;
39
40
40
41
const Stream = module . exports = require ( 'internal/streams/legacy' ) . Stream ;
41
- Stream . isDisturbed = require ( 'internal/streams/utils' ) . isDisturbed ;
42
+ Stream . isDisturbed = utils . isDisturbed ;
43
+ Stream . isErrored = utils . isErrored ;
42
44
Stream . Readable = require ( 'internal/streams/readable' ) ;
43
45
Stream . Writable = require ( 'internal/streams/writable' ) ;
44
46
Stream . Duplex = require ( 'internal/streams/duplex' ) ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
const common = require ( '../common' ) ;
3
3
const assert = require ( 'assert' ) ;
4
- const { isDisturbed, Readable } = require ( 'stream' ) ;
4
+ const { isDisturbed, isErrored , Readable } = require ( 'stream' ) ;
5
5
6
6
function noop ( ) { }
7
7
8
8
function check ( readable , data , fn ) {
9
9
assert . strictEqual ( readable . readableDidRead , false ) ;
10
10
assert . strictEqual ( isDisturbed ( readable ) , false ) ;
11
+ assert . strictEqual ( isErrored ( readable ) , false ) ;
11
12
if ( data === - 1 ) {
12
- readable . on ( 'error' , common . mustCall ( ) ) ;
13
+ readable . on ( 'error' , common . mustCall ( ( ) => {
14
+ assert . strictEqual ( isErrored ( readable ) , true ) ;
15
+ } ) ) ;
13
16
readable . on ( 'data' , common . mustNotCall ( ) ) ;
14
17
readable . on ( 'end' , common . mustNotCall ( ) ) ;
15
18
} else {
Original file line number Diff line number Diff line change 2
2
'use strict' ;
3
3
4
4
const common = require ( '../common' ) ;
5
- const { isDisturbed } = require ( 'stream' ) ;
5
+ const { isDisturbed, isErrored } = require ( 'stream' ) ;
6
6
const assert = require ( 'assert' ) ;
7
7
const {
8
8
isPromise,
@@ -1572,3 +1572,19 @@ class Source {
1572
1572
isDisturbed ( stream , true ) ;
1573
1573
} ) ( ) . then ( common . mustCall ( ) ) ;
1574
1574
}
1575
+
1576
+
1577
+ {
1578
+ const stream = new ReadableStream ( {
1579
+ pull : common . mustCall ( ( controller ) => {
1580
+ controller . error ( new Error ( ) ) ;
1581
+ } ) ,
1582
+ } ) ;
1583
+
1584
+ const reader = stream . getReader ( ) ;
1585
+ ( async ( ) => {
1586
+ isErrored ( stream , false ) ;
1587
+ await reader . read ( ) . catch ( common . mustCall ( ) ) ;
1588
+ isErrored ( stream , true ) ;
1589
+ } ) ( ) . then ( common . mustCall ( ) ) ;
1590
+ }
Original file line number Diff line number Diff line change @@ -206,6 +206,10 @@ const customTypesMap = {
206
206
'stream.Readable' : 'stream.html#class-streamreadable' ,
207
207
'stream.Transform' : 'stream.html#class-streamtransform' ,
208
208
'stream.Writable' : 'stream.html#class-streamwritable' ,
209
+ 'Duplex' : 'stream.html#class-streamduplex' ,
210
+ 'Readable' : 'stream.html#class-streamreadable' ,
211
+ 'Transform' : 'stream.html#class-streamtransform' ,
212
+ 'Writable' : 'stream.html#class-streamwritable' ,
209
213
210
214
'Immediate' : 'timers.html#class-immediate' ,
211
215
'Timeout' : 'timers.html#class-timeout' ,
You can’t perform that action at this time.
0 commit comments