Skip to content

Commit

Permalink
stream: writable.end should return this.
Browse files Browse the repository at this point in the history
PR-URL: nodejs#18780
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
mcollina authored and MayaLekova committed May 8, 2018
1 parent 85889d1 commit 35ee7c7
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 35ee7c7

Please sign in to comment.