File tree Expand file tree Collapse file tree 5 files changed +40
-4
lines changed Expand file tree Collapse file tree 5 files changed +40
-4
lines changed Original file line number Diff line number Diff line change @@ -2211,6 +2211,19 @@ added: REPLACEME
22112211
22122212Returns whether the stream has encountered an error.
22132213
2214+ ### ` stream.isReadable(stream) `
2215+
2216+ <!-- YAML
2217+ added: REPLACEME
2218+ -->
2219+
2220+ > Stability: 1 - Experimental
2221+
2222+ * ` stream ` {Readable|Duplex|ReadableStream}
2223+ * Returns: {boolean}
2224+
2225+ Returns whether the stream is readable.
2226+
22142227### ` stream.Readable.toWeb(streamReadable) `
22152228
22162229<!-- YAML
Original file line number Diff line number Diff line change 88
99const kDestroyed = Symbol ( 'kDestroyed' ) ;
1010const kIsErrored = Symbol ( 'kIsErrored' ) ;
11+ const kIsReadable = Symbol ( 'kIsReadable' ) ;
1112const kIsDisturbed = Symbol ( 'kIsDisturbed' ) ;
1213
1314function isReadableNodeStream ( obj ) {
@@ -120,6 +121,7 @@ function isDisturbed(stream) {
120121}
121122
122123function isReadable ( stream ) {
124+ if ( stream && stream [ kIsReadable ] != null ) return stream [ kIsReadable ] ;
123125 const r = isReadableNodeStream ( stream ) ;
124126 if ( r === null || typeof stream ?. readable !== 'boolean' ) return null ;
125127 if ( isDestroyed ( stream ) ) return false ;
@@ -235,15 +237,16 @@ function isErrored(stream) {
235237
236238module . exports = {
237239 isDisturbed,
238- isErrored,
239240 kIsDisturbed,
241+ isErrored,
240242 kIsErrored,
243+ isReadable,
244+ kIsReadable,
241245 isClosed,
242246 isDestroyed,
243247 isDuplexNodeStream,
244248 isFinished,
245249 isIterable,
246- isReadable,
247250 isReadableNodeStream,
248251 isReadableEnded,
249252 isReadableFinished,
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ const {
8383const {
8484 kIsDisturbed,
8585 kIsErrored,
86+ kIsReadable,
8687} = require ( 'internal/streams/utils' ) ;
8788
8889const {
@@ -261,6 +262,10 @@ class ReadableStream {
261262 return this [ kState ] . state === 'errored' ;
262263 }
263264
265+ get [ kIsReadable ] ( ) {
266+ return this [ kState ] . state === 'readable' ;
267+ }
268+
264269 /**
265270 * @readonly
266271 * @type {boolean }
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ const utils = require('internal/streams/utils');
4444const Stream = module . exports = require ( 'internal/streams/legacy' ) . Stream ;
4545Stream . isDisturbed = utils . isDisturbed ;
4646Stream . isErrored = utils . isErrored ;
47+ Stream . isReadable = utils . isReadable ;
4748Stream . Readable = require ( 'internal/streams/readable' ) ;
4849for ( const key of ObjectKeys ( operators ) ) {
4950 const op = operators [ key ] ;
Original file line number Diff line number Diff line change 22'use strict' ;
33
44const common = require ( '../common' ) ;
5- const { isDisturbed, isErrored } = require ( 'stream' ) ;
5+ const { isDisturbed, isErrored, isReadable } = require ( 'stream' ) ;
66const assert = require ( 'assert' ) ;
77const {
88 isPromise,
@@ -1573,7 +1573,6 @@ class Source {
15731573 } ) ( ) . then ( common . mustCall ( ) ) ;
15741574}
15751575
1576-
15771576{
15781577 const stream = new ReadableStream ( {
15791578 pull : common . mustCall ( ( controller ) => {
@@ -1588,3 +1587,18 @@ class Source {
15881587 isErrored ( stream , true ) ;
15891588 } ) ( ) . then ( common . mustCall ( ) ) ;
15901589}
1590+
1591+ {
1592+ const stream = new ReadableStream ( {
1593+ pull : common . mustCall ( ( controller ) => {
1594+ controller . error ( new Error ( ) ) ;
1595+ } ) ,
1596+ } ) ;
1597+
1598+ const reader = stream . getReader ( ) ;
1599+ ( async ( ) => {
1600+ isReadable ( stream , true ) ;
1601+ await reader . read ( ) . catch ( common . mustCall ( ) ) ;
1602+ isReadable ( stream , false ) ;
1603+ } ) ( ) . then ( common . mustCall ( ) ) ;
1604+ }
You can’t perform that action at this time.
0 commit comments