Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
stream: writable.end should return this.
  • Loading branch information
mcollina committed Feb 15, 2018
commit 3d6756da423075234a421327798537ce8a3e241d
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);