Skip to content

Commit

Permalink
net: replace usage of internal stream state with public api
Browse files Browse the repository at this point in the history
Refs: #445

PR-URL: #34885
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ricky Zhou <[email protected]>
  • Loading branch information
lundibundi authored and richardlau committed Sep 1, 2020
1 parent 94528f5 commit fcb211f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,19 +805,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

0 comments on commit fcb211f

Please sign in to comment.