diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index 92e982e4821586..6275cee8b1e86b 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -860,6 +860,17 @@ ObjectDefineProperties(Writable.prototype, { return this._writableState ? this._writableState.errored : null; } }, + + writableAborted: { + enumerable: false, + get: function() { + return !!( + this._writableState.writable && + (this._writableState.destroyed || this._writableState.errored) && + !this._writableState.finished + ); + } + }, }); const destroy = destroyImpl.destroy; diff --git a/test/parallel/test-stream-writable-aborted.js b/test/parallel/test-stream-writable-aborted.js new file mode 100644 index 00000000000000..83f762e006eb7a --- /dev/null +++ b/test/parallel/test-stream-writable-aborted.js @@ -0,0 +1,25 @@ +'use strict'; + +const assert = require('assert'); +const { Writable } = require('stream'); + +{ + const writable = new Writable({ + write() { + } + }); + assert.strictEqual(writable.writableAborted, false); + writable.destroy(); + assert.strictEqual(writable.writableAborted, true); +} + +{ + const writable = new writable({ + read() { + } + }); + assert.strictEqual(writable.writableAborted, false); + writable.end(); + writable.destroy() + assert.strictEqual(writable.writableAborted, true); +}