Skip to content

Commit

Permalink
websocket: use Buffer.allocUnsafe (nodejs#1817)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and anonrig committed Apr 4, 2023
1 parent 7338154 commit 8af58e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/websocket/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ class WebsocketFrameSend {
payloadLength = 126
}

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

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

Expand Down
1 change: 1 addition & 0 deletions lib/websocket/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class ByteParser extends Writable {
const buffer = this.consume(8)

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

0 comments on commit 8af58e0

Please sign in to comment.