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
21542154
21552155Returns whether the stream has been read from or cancelled.
21562156
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+
21572208### ` stream.Duplex.from(src) `
21582209
21592210<!-- YAML
Original file line number Diff line number Diff line change 66 SymbolIterator,
77} = primordials ;
88
9+ const kDestroyed = Symbol ( 'kDestroyed' ) ;
10+ const kIsErrored = Symbol ( 'kIsErrored' ) ;
911const kIsDisturbed = Symbol ( 'kIsDisturbed' ) ;
1012
1113function isReadableNodeStream ( obj ) {
@@ -212,10 +214,30 @@ function willEmitClose(stream) {
212214 ) ;
213215}
214216
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+ }
215235
216236module . exports = {
217237 isDisturbed,
238+ isErrored,
218239 kIsDisturbed,
240+ kIsErrored,
219241 isClosed,
220242 isDestroyed,
221243 isDuplexNodeStream,
Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ const {
8282
8383const {
8484 kIsDisturbed,
85+ kIsErrored,
8586} = require ( 'internal/streams/utils' ) ;
8687
8788const {
@@ -241,6 +242,10 @@ class ReadableStream {
241242 return this [ kState ] . disturbed ;
242243 }
243244
245+ get [ kIsErrored ] ( ) {
246+ return this [ kState ] . state === 'errored' ;
247+ }
248+
244249 /**
245250 * @readonly
246251 * @type {boolean }
Original file line number Diff line number Diff line change @@ -36,9 +36,11 @@ const eos = require('internal/streams/end-of-stream');
3636const internalBuffer = require ( 'internal/buffer' ) ;
3737
3838const promises = require ( 'stream/promises' ) ;
39+ const utils = require ( 'internal/streams/utils' ) ;
3940
4041const 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 ;
4244Stream . Readable = require ( 'internal/streams/readable' ) ;
4345Stream . Writable = require ( 'internal/streams/writable' ) ;
4446Stream . Duplex = require ( 'internal/streams/duplex' ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
22const common = require ( '../common' ) ;
33const assert = require ( 'assert' ) ;
4- const { isDisturbed, Readable } = require ( 'stream' ) ;
4+ const { isDisturbed, isErrored , Readable } = require ( 'stream' ) ;
55
66function noop ( ) { }
77
88function check ( readable , data , fn ) {
99 assert . strictEqual ( readable . readableDidRead , false ) ;
1010 assert . strictEqual ( isDisturbed ( readable ) , false ) ;
11+ assert . strictEqual ( isErrored ( readable ) , false ) ;
1112 if ( data === - 1 ) {
12- readable . on ( 'error' , common . mustCall ( ) ) ;
13+ readable . on ( 'error' , common . mustCall ( ( ) => {
14+ assert . strictEqual ( isErrored ( readable ) , true ) ;
15+ } ) ) ;
1316 readable . on ( 'data' , common . mustNotCall ( ) ) ;
1417 readable . on ( 'end' , common . mustNotCall ( ) ) ;
1518 } else {
Original file line number Diff line number Diff line change 22'use strict' ;
33
44const common = require ( '../common' ) ;
5- const { isDisturbed } = require ( 'stream' ) ;
5+ const { isDisturbed, isErrored } = require ( 'stream' ) ;
66const assert = require ( 'assert' ) ;
77const {
88 isPromise,
@@ -1572,3 +1572,19 @@ class Source {
15721572 isDisturbed ( stream , true ) ;
15731573 } ) ( ) . then ( common . mustCall ( ) ) ;
15741574}
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 = {
206206 'stream.Readable' : 'stream.html#class-streamreadable' ,
207207 'stream.Transform' : 'stream.html#class-streamtransform' ,
208208 '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' ,
209213
210214 'Immediate' : 'timers.html#class-immediate' ,
211215 'Timeout' : 'timers.html#class-timeout' ,
You can’t perform that action at this time.
0 commit comments