Skip to content

Commit

Permalink
stream: writable.end should return this.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mcollina committed Feb 19, 2018
1 parent e91ea21 commit f6721c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ See also: [`writable.uncork()`][].
<!-- YAML
added: v0.9.4
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/18780
description: This method now returns a reference to `writable`.
- version: v8.0.0
pr-url: https://github.com/nodejs/node/pull/11608
description: The `chunk` argument can now be a `Uint8Array` instance.
Expand All @@ -366,6 +369,7 @@ changes:
other than `null`.
* `encoding` {string} The encoding, if `chunk` is a string
* `callback` {Function} Optional callback for when the stream is finished
* Returns: {this}

Calling the `writable.end()` method signals that no more data will be written
to the [Writable][]. The optional `chunk` and `encoding` arguments allow one
Expand Down
2 changes: 2 additions & 0 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ Writable.prototype.end = function(chunk, encoding, cb) {
// ignore unnecessary end() calls.
if (!state.ending)
endWritable(this, state, cb);

return this;
};

Object.defineProperty(Writable.prototype, 'writableLength', {
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-stream-writableState-ending.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ writable.on('finish', () => {
testStates(true, true, true);
});

writable.end('testing function end()', () => {
const result = writable.end('testing function end()', () => {
// ending, finished, ended = true.
testStates(true, true, true);
});

// end returns the writable instance
assert.strictEqual(result, writable);

// ending, ended = true.
// finished = false.
testStates(true, false, true);

0 comments on commit f6721c2

Please sign in to comment.