@@ -11,6 +11,7 @@ const {
11
11
failWebsocketConnection,
12
12
websocketMessageReceived,
13
13
utf8Decode,
14
+ bufferConcat,
14
15
isControlFrame,
15
16
isTextBinaryFrame,
16
17
isContinuationFrame
@@ -33,6 +34,7 @@ class ByteParser extends Writable {
33
34
34
35
#info = { }
35
36
#fragments = [ ]
37
+ #fragmentsBytes = 0
36
38
37
39
/** @type {Map<string, PerMessageDeflate> } */
38
40
#extensions
@@ -208,15 +210,17 @@ class ByteParser extends Writable {
208
210
} else {
209
211
if ( ! this . #info. compressed ) {
210
212
this . #fragments. push ( body )
213
+ this . #fragmentsBytes += body . length
211
214
212
215
// If the frame is not fragmented, a message has been received.
213
216
// If the frame is fragmented, it will terminate with a fin bit set
214
217
// and an opcode of 0 (continuation), therefore we handle that when
215
218
// parsing continuation frames, not here.
216
219
if ( ! this . #info. fragmented && this . #info. fin ) {
217
- const fullMessage = Buffer . concat ( this . #fragments)
220
+ const fullMessage = bufferConcat ( this . #fragments, this . #fragmentsBytes )
218
221
websocketMessageReceived ( this . ws , this . #info. binaryType , fullMessage )
219
222
this . #fragments. length = 0
223
+ this . #fragmentsBytes = 0
220
224
}
221
225
222
226
this . #state = parserStates . INFO
@@ -236,12 +240,13 @@ class ByteParser extends Writable {
236
240
return
237
241
}
238
242
239
- websocketMessageReceived ( this . ws , this . #info. binaryType , Buffer . concat ( this . #fragments) )
243
+ websocketMessageReceived ( this . ws , this . #info. binaryType , bufferConcat ( this . #fragments, this . #fragmentsBytes ) )
240
244
241
245
this . #loop = true
242
246
this . #state = parserStates . INFO
243
247
this . run ( callback )
244
248
this . #fragments. length = 0
249
+ this . #fragmentsBytes = 0
245
250
} )
246
251
247
252
this . #loop = false
0 commit comments