| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2228,6 +2228,19 @@ added: v17.3.0 | |||
| 2228 | 2228 | ||
| 2229 | 2229 | Returns whether the stream has encountered an error. | |
| 2230 | 2230 | ||
| 2231 | + ### `stream.isReadable(stream)` | ||
| 2232 | + | ||
| 2233 | + <!-- YAML | ||
| 2234 | + added: REPLACEME | ||
| 2235 | + --> | ||
| 2236 | + | ||
| 2237 | + > Stability: 1 - Experimental | ||
| 2238 | + | ||
| 2239 | + * `stream` {Readable|Duplex|ReadableStream} | ||
| 2240 | + * Returns: {boolean} | ||
| 2241 | + | ||
| 2242 | + Returns whether the stream is readable. | ||
| 2243 | + | ||
| 2231 | 2244 | ### `stream.Readable.toWeb(streamReadable)` | |
| 2232 | 2245 | ||
| 2233 | 2246 | <!-- YAML | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ const { | |||
| 8 | 8 | ||
| 9 | 9 | const kDestroyed = Symbol('kDestroyed'); | |
| 10 | 10 | const kIsErrored = Symbol('kIsErrored'); | |
| 11 | + const kIsReadable = Symbol('kIsReadable'); | ||
| 11 | 12 | const kIsDisturbed = Symbol('kIsDisturbed'); | |
| 12 | 13 | ||
| 13 | 14 | function isReadableNodeStream(obj, strict = false) { | |
@@ -116,6 +117,7 @@ function isReadableFinished(stream, strict) { | |||
| 116 | 117 | } | |
| 117 | 118 | ||
| 118 | 119 | function isReadable(stream) { | |
| 120 | + if (stream && stream[kIsReadable] != null) return stream[kIsReadable]; | ||
| 119 | 121 | const r = isReadableNodeStream(stream); | |
| 120 | 122 | if (r === null || typeof stream?.readable !== 'boolean') return null; | |
| 121 | 123 | if (isDestroyed(stream)) return false; | |
@@ -232,15 +234,16 @@ function isErrored(stream) { | |||
| 232 | 234 | module.exports = { | |
| 233 | 235 | kDestroyed, | |
| 234 | 236 | isDisturbed, | |
| 235 | - isErrored, | ||
| 236 | 237 | kIsDisturbed, | |
| 238 | + isErrored, | ||
| 237 | 239 | kIsErrored, | |
| 240 | + isReadable, | ||
| 241 | + kIsReadable, | ||
| 238 | 242 | isClosed, | |
| 239 | 243 | isDestroyed, | |
| 240 | 244 | isDuplexNodeStream, | |
| 241 | 245 | isFinished, | |
| 242 | 246 | isIterable, | |
| 243 | - isReadable, | ||
| 244 | 247 | isReadableNodeStream, | |
| 245 | 248 | isReadableEnded, | |
| 246 | 249 | isReadableFinished, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,6 +83,7 @@ const { | |||
| 83 | 83 | const { | |
| 84 | 84 | kIsDisturbed, | |
| 85 | 85 | kIsErrored, | |
| 86 | + kIsReadable, | ||
| 86 | 87 | } = require('internal/streams/utils'); | |
| 87 | 88 | ||
| 88 | 89 | const { | |
@@ -261,6 +262,10 @@ class ReadableStream { | |||
| 261 | 262 | return this[kState].state === 'errored'; | |
| 262 | 263 | } | |
| 263 | 264 | ||
| 265 | + get [kIsReadable]() { | ||
| 266 | + return this[kState].state === 'readable'; | ||
| 267 | + } | ||
| 268 | + | ||
| 264 | 269 | /** | |
| 265 | 270 | * @readonly | |
| 266 | 271 | * @type {boolean} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,7 @@ const utils = require('internal/streams/utils'); | |||
| 44 | 44 | const Stream = module.exports = require('internal/streams/legacy').Stream; | |
| 45 | 45 | Stream.isDisturbed = utils.isDisturbed; | |
| 46 | 46 | Stream.isErrored = utils.isErrored; | |
| 47 | + Stream.isReadable = utils.isReadable; | ||
| 47 | 48 | Stream.Readable = require('internal/streams/readable'); | |
| 48 | 49 | for (const key of ObjectKeys(operators)) { | |
| 49 | 50 | const op = operators[key]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | 'use strict'; | |
| 3 | 3 | ||
| 4 | 4 | const common = require('../common'); | |
| 5 | - const { isDisturbed, isErrored } = require('stream'); | ||
| 5 | + const { isDisturbed, isErrored, isReadable } = require('stream'); | ||
| 6 | 6 | const assert = require('assert'); | |
| 7 | 7 | const { | |
| 8 | 8 | isPromise, | |
@@ -1573,7 +1573,6 @@ class Source { | |||
| 1573 | 1573 | })().then(common.mustCall()); | |
| 1574 | 1574 | } | |
| 1575 | 1575 | ||
| 1576 | - | ||
| 1577 | 1576 | { | |
| 1578 | 1577 | const stream = new ReadableStream({ | |
| 1579 | 1578 | pull: common.mustCall((controller) => { | |
@@ -1588,3 +1587,18 @@ class Source { | |||
| 1588 | 1587 | isErrored(stream, true); | |
| 1589 | 1588 | })().then(common.mustCall()); | |
| 1590 | 1589 | } | |
| 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments