Skip to content
Closed
Changes from all commits
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
10 changes: 10 additions & 0 deletions lib/_stream_writable.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,6 +39,7 @@ const {
module.exports = Writable;
Writable.WritableState = WritableState;

const debug = require('internal/util/debuglog').debuglog('stream');
const EE = require('events');
const Stream = require('stream');
const { Buffer } = require('buffer');
Expand DownExpand Up@@ -257,6 +258,7 @@ function Writable(options) {

// Otherwise people can pipe Writable streams, which is just wrong.
Writable.prototype.pipe = function() {
debug('pipe');
errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
};

Expand DownExpand Up@@ -298,6 +300,7 @@ Writable.prototype.write = function(chunk, encoding, cb) {
}

if (err) {
debug('Error', err);
process.nextTick(cb, err);
errorOrDestroy(this, err, true);
return false;
Expand All@@ -308,10 +311,12 @@ Writable.prototype.write = function(chunk, encoding, cb) {
};

Writable.prototype.cork = function() {
debug('cork');
this._writableState.corked++;
};

Writable.prototype.uncork = function() {
debug('uncork');
const state = this._writableState;

if (state.corked) {
Expand DownExpand Up@@ -372,6 +377,7 @@ function writeOrBuffer(stream, state, chunk, encoding, cb) {
}

function doWrite(stream, state, writev, len, chunk, encoding, cb) {
debug('Writting');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

debug('Writing %o', chunk); would be more useful

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thank you sr, fixing this!

state.writelen = len;
state.writecb = cb;
state.writing = true;
Expand All@@ -386,6 +392,7 @@ function doWrite(stream, state, writev, len, chunk, encoding, cb) {
}

function onwriteError(stream, state, er, cb) {
debug('write error', stream);
--state.pendingcb;

cb(er);
Expand DownExpand Up@@ -414,6 +421,7 @@ function onwrite(stream, er) {
state.writelen = 0;

if (er) {
debug('error', stream);
state.errored = true;
if (sync) {
process.nextTick(onwriteError, stream, state, er, cb);
Expand DownExpand Up@@ -459,6 +467,7 @@ function afterWrite(stream, state, count, cb) {
state.needDrain;
if (needDrain) {
state.needDrain = false;
debug('drain', state.needDrain);
stream.emit('drain');
}

Expand DownExpand Up@@ -688,6 +697,7 @@ function endWritable(stream, state, cb) {
}
state.ended = true;
stream.writable = false;
debug('endWritable', state.ended);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the state.ended will always be true so I'm not sure how useful this log is.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Get it!

}

function onCorkedFinish(corkReq, state, err) {
Expand Down