Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: replace usage of internal stream state with public api #34885

Closed
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
15 changes: 7 additions & 8 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,19 +789,18 @@ protoGetter('_bytesDispatched', function _bytesDispatched() {

protoGetter('bytesWritten', function bytesWritten() {
let bytes = this._bytesDispatched;
const state = this._writableState;
const data = this._pendingData;
const encoding = this._pendingEncoding;
const writableBuffer = this.writableBuffer;

if (!state)
if (!writableBuffer)
return undefined;

this.writableBuffer.forEach(function(el) {
if (el.chunk instanceof Buffer)
bytes += el.chunk.length;
else
bytes += Buffer.byteLength(el.chunk, el.encoding);
});
for (const el of writableBuffer) {
bytes += el.chunk instanceof Buffer ?
el.chunk.length :
Buffer.byteLength(el.chunk, el.encoding);
}

if (ArrayIsArray(data)) {
// Was a writev, iterate over chunks to get total length
Expand Down