Skip to content

Commit b6844f0

Browse files
authored
websocket: use Buffer.allocUnsafe (nodejs#1817)
1 parent 5165d67 commit b6844f0

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/websocket/frame.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ class WebsocketFrameSend {
2727
payloadLength = 126
2828
}
2929

30-
// TODO: switch to Buffer.allocUnsafe
31-
const buffer = Buffer.alloc(bodyLength + offset)
30+
const buffer = Buffer.allocUnsafe(bodyLength + offset)
3231

32+
// Clear first 2 bytes, everything else is overwritten
33+
buffer[0] = buffer[1] = 0
3334
buffer[0] |= 0x80 // FIN
3435
buffer[0] = (buffer[0] & 0xF0) + opcode // opcode
3536

lib/websocket/receiver.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class ByteParser extends Writable {
198198
const buffer = this.consume(8)
199199

200200
// TODO: optimize this
201+
// TODO: this likely doesn't work because it returns a bigint
201202
this.#info.payloadLength = buffer.readBigUint64BE(0)
202203
this.#state = parserStates.READ_DATA
203204
} else if (this.#state === parserStates.READ_DATA) {

0 commit comments

Comments
 (0)