diff --git a/lib/websocket/websocket.js b/lib/websocket/websocket.js index 366b6aa3e27..79c9be439c1 100644 --- a/lib/websocket/websocket.js +++ b/lib/websocket/websocket.js @@ -309,23 +309,14 @@ class WebSocket extends EventTarget { // not throw an exception must increase the bufferedAmount attribute // by the length of data’s buffer in bytes. - const ab = new ArrayBuffer(data.byteLength) + const ab = Buffer.from(data, data.byteOffset, data.byteLength) - if (Buffer.isBuffer(data)) { - // new Buffer signature is deprecated - Buffer.from(ab).set(data) - } else { - new data.constructor(ab).set(data) - } - - const value = Buffer.from(ab) - - const frame = new WebsocketFrameSend(value) + const frame = new WebsocketFrameSend(ab) const buffer = frame.createFrame(opcodes.BINARY) - this.#bufferedAmount += value.byteLength + this.#bufferedAmount += ab.byteLength socket.write(buffer, () => { - this.#bufferedAmount -= value.byteLength + this.#bufferedAmount -= ab.byteLength }) } else if (isBlobLike(data)) { // If the WebSocket connection is established, and the WebSocket