Skip to content

Commit 3c4abe0

Browse files
lundibundiaddaleax
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 cda459e commit 3c4abe0

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Diff for: lib/net.js

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

808808
protoGetter('bytesWritten', function bytesWritten() {
809809
let bytes = this._bytesDispatched;
810-
const state = this._writableState;
811810
const data = this._pendingData;
812811
const encoding = this._pendingEncoding;
812+
const writableBuffer = this.writableBuffer;
813813

814-
if (!state)
814+
if (!writableBuffer)
815815
return undefined;
816816

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

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

0 commit comments

Comments
 (0)