Skip to content

Commit a36b7d8

Browse files
lundibundinodejs-github-bot
authored andcommitted
net: replace usage of internal stream state with public api
Refs: #445 PR-URL: #34885 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
1 parent 7fca0df commit a36b7d8

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/net.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -789,19 +789,18 @@ protoGetter('_bytesDispatched', function _bytesDispatched() {
789789

790790
protoGetter('bytesWritten', function bytesWritten() {
791791
let bytes = this._bytesDispatched;
792-
const state = this._writableState;
793792
const data = this._pendingData;
794793
const encoding = this._pendingEncoding;
794+
const writableBuffer = this.writableBuffer;
795795

796-
if (!state)
796+
if (!writableBuffer)
797797
return undefined;
798798

799-
this.writableBuffer.forEach(function(el) {
800-
if (el.chunk instanceof Buffer)
801-
bytes += el.chunk.length;
802-
else
803-
bytes += Buffer.byteLength(el.chunk, el.encoding);
804-
});
799+
for (const el of writableBuffer) {
800+
bytes += el.chunk instanceof Buffer ?
801+
el.chunk.length :
802+
Buffer.byteLength(el.chunk, el.encoding);
803+
}
805804

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

0 commit comments

Comments
 (0)