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‎

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

806806
protoGetter('bytesWritten',functionbytesWritten(){
807807
letbytes=this._bytesDispatched;
808-
conststate=this._writableState;
809808
constdata=this._pendingData;
810809
constencoding=this._pendingEncoding;
810+
constwritableBuffer=this.writableBuffer;
811811

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

815-
this.writableBuffer.forEach(function(el){
816-
if(el.chunkinstanceofBuffer)
817-
bytes+=el.chunk.length;
818-
else
819-
bytes+=Buffer.byteLength(el.chunk,el.encoding);
820-
});
815+
for(constelofwritableBuffer){
816+
bytes+=el.chunkinstanceofBuffer ?
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)