Skip to content

Commit fcb211f

Browse files
lundibundirichardlau
authored andcommitted
net: replace usage of internal stream state with public api
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]>
1 parent 94528f5 commit fcb211f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/net.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -805,19 +805,18 @@ protoGetter('_bytesDispatched', function _bytesDispatched() {
805805

806806
protoGetter('bytesWritten', function bytesWritten() {
807807
let bytes = this._bytesDispatched;
808-
const state = this._writableState;
809808
const data = this._pendingData;
810809
const encoding = this._pendingEncoding;
810+
const writableBuffer = this.writableBuffer;
811811

812-
if (!state)
812+
if (!writableBuffer)
813813
return undefined;
814814

815-
this.writableBuffer.forEach(function(el) {
816-
if (el.chunk instanceof Buffer)
817-
bytes += el.chunk.length;
818-
else
819-
bytes += Buffer.byteLength(el.chunk, el.encoding);
820-
});
815+
for (const el of writableBuffer) {
816+
bytes += el.chunk instanceof Buffer ?
817+
el.chunk.length :
818+
Buffer.byteLength(el.chunk, el.encoding);
819+
}
821820

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

0 commit comments

Comments
 (0)