Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(websocket): simplify typedarray copying #1854

Merged
merged 3 commits into from
Jan 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions lib/websocket/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down