Skip to content

Commit f6721c2

Browse files
committed
stream: writable.end should return this.
PR-URL: #18780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent e91ea21 commit f6721c2

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/api/stream.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ See also: [`writable.uncork()`][].
355355
<!-- YAML
356356
added: v0.9.4
357357
changes:
358+
- version: REPLACEME
359+
pr-url: https://github.com/nodejs/node/pull/18780
360+
description: This method now returns a reference to `writable`.
358361
- version: v8.0.0
359362
pr-url: https://github.com/nodejs/node/pull/11608
360363
description: The `chunk` argument can now be a `Uint8Array` instance.
@@ -366,6 +369,7 @@ changes:
366369
other than `null`.
367370
* `encoding` {string} The encoding, if `chunk` is a string
368371
* `callback` {Function} Optional callback for when the stream is finished
372+
* Returns: {this}
369373

370374
Calling the `writable.end()` method signals that no more data will be written
371375
to the [Writable][]. The optional `chunk` and `encoding` arguments allow one

lib/_stream_writable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ Writable.prototype.end = function(chunk, encoding, cb) {
570570
// ignore unnecessary end() calls.
571571
if (!state.ending)
572572
endWritable(this, state, cb);
573+
574+
return this;
573575
};
574576

575577
Object.defineProperty(Writable.prototype, 'writableLength', {

test/parallel/test-stream-writableState-ending.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ writable.on('finish', () => {
2424
testStates(true, true, true);
2525
});
2626

27-
writable.end('testing function end()', () => {
27+
const result = writable.end('testing function end()', () => {
2828
// ending, finished, ended = true.
2929
testStates(true, true, true);
3030
});
3131

32+
// end returns the writable instance
33+
assert.strictEqual(result, writable);
34+
3235
// ending, ended = true.
3336
// finished = false.
3437
testStates(true, false, true);

0 commit comments

Comments
 (0)