property
ServerWebSocket.binaryType
binaryType?: 'arraybuffer' | 'blob' | 'uint8array' | 'nodebuffer'
Sets how binary data is returned in events.
- if
nodebuffer, binary data is returned asBufferobjects. (default) - if
arraybuffer, binary data is returned asArrayBufferobjects. - if
uint8array, binary data is returned asUint8Arrayobjects. - if
blob, binary data is returned asBlobobjects.
This applies to binary messages and to the payloads of pings and pongs.
Bun.serve({
websocket: {
open(ws) {
ws.binaryType = "uint8array";
},
message(ws, message) {
console.log(message instanceof Uint8Array); // true, for a binary message
},
},
// ...
});