| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -456,6 +456,16 @@ further errors except from `_destroy()` may be emitted as `'error'`. | |||
| 456 | 456 | Implementors should not override this method, | |
| 457 | 457 | but instead implement [`writable._destroy()`][writable-_destroy]. | |
| 458 | 458 | ||
| 459 | + ##### `writable.closed` | ||
| 460 | + | ||
| 461 | + <!-- YAML | ||
| 462 | + added: REPLACEME | ||
| 463 | + --> | ||
| 464 | + | ||
| 465 | + * {boolean} | ||
| 466 | + | ||
| 467 | + Is `true` after `'close'` has been emitted. | ||
| 468 | + | ||
| 459 | 469 | ##### `writable.destroyed` | |
| 460 | 470 | ||
| 461 | 471 | <!-- YAML | |
@@ -611,6 +621,17 @@ added: | |||
| 611 | 621 | Number of times [`writable.uncork()`][stream-uncork] needs to be | |
| 612 | 622 | called in order to fully uncork the stream. | |
| 613 | 623 | ||
| 624 | + ##### `writable.writableErrored` | ||
| 625 | + | ||
| 626 | + <!-- YAML | ||
| 627 | + added: | ||
| 628 | + REPLACEME | ||
| 629 | + --> | ||
| 630 | + | ||
| 631 | + * {Error} | ||
| 632 | + | ||
| 633 | + Returns error if the stream has been destroyed with an error. | ||
| 634 | + | ||
| 614 | 635 | ##### `writable.writableFinished` | |
| 615 | 636 | ||
| 616 | 637 | <!-- YAML | |
@@ -1080,14 +1101,24 @@ further errors except from `_destroy()` may be emitted as `'error'`. | |||
| 1080 | 1101 | Implementors should not override this method, but instead implement | |
| 1081 | 1102 | [`readable._destroy()`][readable-_destroy]. | |
| 1082 | 1103 | ||
| 1083 | - ##### `readable.destroyed` | ||
| 1104 | + ##### `readable.closed` | ||
| 1084 | 1105 | ||
| 1085 | 1106 | <!-- YAML | |
| 1086 | 1107 | added: v8.0.0 | |
| 1087 | 1108 | --> | |
| 1088 | 1109 | ||
| 1089 | 1110 | * {boolean} | |
| 1090 | 1111 | ||
| 1112 | + Is `true` after `'close'` has been emitted. | ||
| 1113 | + | ||
| 1114 | + ##### `readable.destroyed` | ||
| 1115 | + | ||
| 1116 | + <!-- YAML | ||
| 1117 | + added: REPLACEME | ||
| 1118 | + --> | ||
| 1119 | + | ||
| 1120 | + * {boolean} | ||
| 1121 | + | ||
| 1091 | 1122 | Is `true` after [`readable.destroy()`][readable-destroy] has been called. | |
| 1092 | 1123 | ||
| 1093 | 1124 | ##### `readable.isPaused()` | |
@@ -1346,6 +1377,17 @@ added: v12.9.0 | |||
| 1346 | 1377 | ||
| 1347 | 1378 | Becomes `true` when [`'end'`][] event is emitted. | |
| 1348 | 1379 | ||
| 1380 | + ##### `readable.readableErrored` | ||
| 1381 | + | ||
| 1382 | + <!-- YAML | ||
| 1383 | + added: | ||
| 1384 | + REPLACEME | ||
| 1385 | + --> | ||
| 1386 | + | ||
| 1387 | + * {Error} | ||
| 1388 | + | ||
| 1389 | + Returns error if the stream has been destroyed with an error. | ||
| 1390 | + | ||
| 1349 | 1391 | ##### `readable.readableFlowing` | |
| 1350 | 1392 | ||
| 1351 | 1393 | <!-- YAML | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -107,12 +107,9 @@ const FileHandleOperations = (handle) => { | |||
| 107 | 107 | ||
| 108 | 108 | function close(stream, err, cb) { | |
| 109 | 109 | if (!stream.fd) { | |
| 110 | - // TODO(ronag) | ||
| 111 | - // stream.closed = true; | ||
| 112 | 110 | cb(err); | |
| 113 | 111 | } else { | |
| 114 | 112 | stream[kFs].close(stream.fd, (er) => { | |
| 115 | - stream.closed = true; | ||
| 116 | 113 | cb(er || err); | |
| 117 | 114 | }); | |
| 118 | 115 | stream.fd = null; | |
@@ -186,7 +183,6 @@ function ReadStream(path, options) { | |||
| 186 | 183 | this.end = options.end; | |
| 187 | 184 | this.pos = undefined; | |
| 188 | 185 | this.bytesRead = 0; | |
| 189 | - this.closed = false; | ||
| 190 | 186 | this[kIsPerformingIO] = false; | |
| 191 | 187 | ||
| 192 | 188 | if (this.start !== undefined) { | |
@@ -358,10 +354,8 @@ function WriteStream(path, options) { | |||
| 358 | 354 | this.start = options.start; | |
| 359 | 355 | this.pos = undefined; | |
| 360 | 356 | this.bytesWritten = 0; | |
| 361 | - this.closed = false; | ||
| 362 | 357 | this[kIsPerformingIO] = false; | |
| 363 | 358 | ||
| 364 | - | ||
| 365 | 359 | if (this.start !== undefined) { | |
| 366 | 360 | validateInteger(this.start, 'start', 0); | |
| 367 | 361 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,9 +22,11 @@ const { | |||
| 22 | 22 | isReadable, | |
| 23 | 23 | isReadableNodeStream, | |
| 24 | 24 | isReadableFinished, | |
| 25 | + isReadableErrored, | ||
| 25 | 26 | isWritable, | |
| 26 | 27 | isWritableNodeStream, | |
| 27 | 28 | isWritableFinished, | |
| 29 | + isWritableErrored, | ||
| 28 | 30 | isNodeStream, | |
| 29 | 31 | willEmitClose: _willEmitClose, | |
| 30 | 32 | } = require('internal/streams/utils'); | |
@@ -110,7 +112,7 @@ function eos(stream, options, callback) { | |||
| 110 | 112 | const onclose = () => { | |
| 111 | 113 | closed = true; | |
| 112 | 114 | ||
| 113 | - const errored = wState?.errored || rState?.errored; | ||
| 115 | + const errored = isWritableErrored(stream) || isReadableErrored(stream); | ||
| 114 | 116 | ||
| 115 | 117 | if (errored && typeof errored !== 'boolean') { | |
| 116 | 118 | return callback.call(stream, errored); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1239,13 +1239,23 @@ ObjectDefineProperties(Readable.prototype, { | |||
| 1239 | 1239 | } | |
| 1240 | 1240 | }, | |
| 1241 | 1241 | ||
| 1242 | + readableErrored: { | ||
| 1243 | + enumerable: false, | ||
| 1244 | + get() { | ||
| 1245 | + return this._readableState ? this._readableState.errored : null; | ||
| 1246 | + } | ||
| 1247 | + }, | ||
| 1248 | + | ||
| 1249 | + closed: { | ||
| 1250 | + get() { | ||
| 1251 | + return this._readableState ? this._readableState.closed : false; | ||
| 1252 | + } | ||
| 1253 | + }, | ||
| 1254 | + | ||
| 1242 | 1255 | destroyed: { | |
| 1243 | 1256 | enumerable: false, | |
| 1244 | 1257 | get() { | |
| 1245 | - if (this._readableState === undefined) { | ||
| 1246 | - return false; | ||
| 1247 | - } | ||
| 1248 | - return this._readableState.destroyed; | ||
| 1258 | + return this._readableState ? this._readableState.destroyed : false; | ||
| 1249 | 1259 | }, | |
| 1250 | 1260 | set(value) { | |
| 1251 | 1261 | // We ignore the value if the stream | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -144,11 +144,39 @@ function isFinished(stream, opts) { | |||
| 144 | 144 | return true; | |
| 145 | 145 | } | |
| 146 | 146 | ||
| 147 | + function isWritableErrored(stream) { | ||
| 148 | + if (!isNodeStream(stream)) { | ||
| 149 | + return null; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + if (stream.writableErrored) { | ||
| 153 | + return stream.writableErrored; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + return stream._writableState?.errored ?? null; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + function isReadableErrored(stream) { | ||
| 160 | + if (!isNodeStream(stream)) { | ||
| 161 | + return null; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + if (stream.readableErrored) { | ||
| 165 | + return stream.readableErrored; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + return stream._readableState?.errored ?? null; | ||
| 169 | + } | ||
| 170 | + | ||
| 147 | 171 | function isClosed(stream) { | |
| 148 | 172 | if (!isNodeStream(stream)) { | |
| 149 | 173 | return null; | |
| 150 | 174 | } | |
| 151 | 175 | ||
| 176 | + if (typeof stream.closed === 'boolean') { | ||
| 177 | + return stream.closed; | ||
| 178 | + } | ||
| 179 | + | ||
| 152 | 180 | const wState = stream._writableState; | |
| 153 | 181 | const rState = stream._readableState; | |
| 154 | 182 | ||
@@ -226,11 +254,13 @@ module.exports = { | |||
| 226 | 254 | isReadableNodeStream, | |
| 227 | 255 | isReadableEnded, | |
| 228 | 256 | isReadableFinished, | |
| 257 | + isReadableErrored, | ||
| 229 | 258 | isNodeStream, | |
| 230 | 259 | isWritable, | |
| 231 | 260 | isWritableNodeStream, | |
| 232 | 261 | isWritableEnded, | |
| 233 | 262 | isWritableFinished, | |
| 263 | + isWritableErrored, | ||
| 234 | 264 | isServerRequest, | |
| 235 | 265 | isServerResponse, | |
| 236 | 266 | willEmitClose, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -768,6 +768,12 @@ function finish(stream, state) { | |||
| 768 | 768 | ||
| 769 | 769 | ObjectDefineProperties(Writable.prototype, { | |
| 770 | 770 | ||
| 771 | + closed: { | ||
| 772 | + get() { | ||
| 773 | + return this._writableState ? this._writableState.closed : false; | ||
| 774 | + } | ||
| 775 | + }, | ||
| 776 | + | ||
| 771 | 777 | destroyed: { | |
| 772 | 778 | get() { | |
| 773 | 779 | return this._writableState ? this._writableState.destroyed : false; | |
@@ -846,7 +852,14 @@ ObjectDefineProperties(Writable.prototype, { | |||
| 846 | 852 | get() { | |
| 847 | 853 | return this._writableState && this._writableState.length; | |
| 848 | 854 | } | |
| 849 | - } | ||
| 855 | + }, | ||
| 856 | + | ||
| 857 | + writableErrored: { | ||
| 858 | + enumerable: false, | ||
| 859 | + get() { | ||
| 860 | + return this._writableState ? this._writableState.errored : null; | ||
| 861 | + } | ||
| 862 | + }, | ||
| 850 | 863 | }); | |
| 851 | 864 | ||
| 852 | 865 | const destroy = destroyImpl.destroy; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -199,7 +199,7 @@ const rangeFile = fixtures.path('x.txt'); | |||
| 199 | 199 | file.on('error', common.mustCall()); | |
| 200 | 200 | ||
| 201 | 201 | process.on('exit', function() { | |
| 202 | - assert(!file.closed); | ||
| 202 | + assert(file.closed); | ||
| 203 | 203 | assert(file.destroyed); | |
| 204 | 204 | }); | |
| 205 | 205 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -271,7 +271,7 @@ if (!common.isWindows) { | |||
| 271 | 271 | file.on('error', common.mustCall()); | |
| 272 | 272 | ||
| 273 | 273 | process.on('exit', function() { | |
| 274 | - assert(!file.closed); | ||
| 274 | + assert(file.closed); | ||
| 275 | 275 | assert(file.destroyed); | |
| 276 | 276 | }); | |
| 277 | 277 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -612,8 +612,10 @@ testClosed((opts) => new Writable({ write() {}, ...opts })); | |||
| 612 | 612 | const w = new Writable(); | |
| 613 | 613 | const _err = new Error(); | |
| 614 | 614 | w.destroy(_err); | |
| 615 | + assert.strictEqual(w.writableErrored, _err); | ||
| 615 | 616 | finished(w, common.mustCall((err) => { | |
| 616 | 617 | assert.strictEqual(_err, err); | |
| 618 | + assert.strictEqual(w.closed, true); | ||
| 617 | 619 | finished(w, common.mustCall((err) => { | |
| 618 | 620 | assert.strictEqual(_err, err); | |
| 619 | 621 | })); | |
@@ -623,7 +625,9 @@ testClosed((opts) => new Writable({ write() {}, ...opts })); | |||
| 623 | 625 | { | |
| 624 | 626 | const w = new Writable(); | |
| 625 | 627 | w.destroy(); | |
| 628 | + assert.strictEqual(w.writableErrored, null); | ||
| 626 | 629 | finished(w, common.mustCall((err) => { | |
| 630 | + assert.strictEqual(w.closed, true); | ||
| 627 | 631 | assert.strictEqual(err.code, 'ERR_STREAM_PREMATURE_CLOSE'); | |
| 628 | 632 | finished(w, common.mustCall((err) => { | |
| 629 | 633 | assert.strictEqual(err.code, 'ERR_STREAM_PREMATURE_CLOSE'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ const assert = require('assert'); | |||
| 13 | 13 | read.on('close', common.mustCall()); | |
| 14 | 14 | ||
| 15 | 15 | read.destroy(); | |
| 16 | + assert.strictEqual(read.readableErrored, null); | ||
| 16 | 17 | assert.strictEqual(read.destroyed, true); | |
| 17 | 18 | } | |
| 18 | 19 | ||
@@ -31,6 +32,7 @@ const assert = require('assert'); | |||
| 31 | 32 | })); | |
| 32 | 33 | ||
| 33 | 34 | read.destroy(expected); | |
| 35 | + assert.strictEqual(read.readableErrored, expected); | ||
| 34 | 36 | assert.strictEqual(read.destroyed, true); | |
| 35 | 37 | } | |
| 36 | 38 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments