Skip to content
Closed
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: delete redundant code
In `Writable.prototype.end()`, `state.ending` is true after calling
`endWritable()` and it doesn't reset to false.

In `Writable.prototype.uncork()`, `state.finished` must be false
if `state.bufferedRequest` is true.
  • Loading branch information
陈刚 committed Jan 14, 2018
commit 4ecb688ea310d57e20382b07ef5ec1e7093a8063
3 changes: 1 addition & 2 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ Writable.prototype.uncork = function() {

if (!state.writing &&
!state.corked &&
!state.finished &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this unused?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state.finished should equal false if state.bufferedRequest isn't null.

!state.bufferProcessing &&
state.bufferedRequest)
clearBuffer(this, state);
Expand Down Expand Up @@ -579,7 +578,7 @@ Writable.prototype.end = function(chunk, encoding, cb) {
}

// ignore unnecessary end() calls.
if (!state.ending && !state.finished)
if (!state.ending)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a behavior change. Can you add a unit test?

Copy link
Copy Markdown
Member Author

@MoonBall MoonBall Jan 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state.finished = true is only in finishMaybe(). If we simplify the finishMaybe(), it should be:

function finishMaybe(stream, state) {
  if (state.ending) {
    state.finished = true;
  }
}

And, state.ending doesn't set to false.
So:

  1. if state.finished is true, state.ending must be true:
    !state.ending && !state.finished equals false && false.
    !state.ending equals false.
    !state.ending && !state.finished equals !state.ending.
  2. if state.finished is false:
    !state.ending && !state.finished equals !state.ending && true.
    !state.ending && !state.finished equals !state.ending.

endWritable(this, state, cb);
};

Expand Down