Update article.md
This commit is contained in:
parent
cdf382de4c
commit
0f391b2e2f
1 changed files with 2 additions and 2 deletions
|
@ -177,12 +177,12 @@ A call `socket.send(body)` allows `body` in string or a binary format, including
|
|||
|
||||
**When we receive the data, text always comes as string. And for binary data, we can choose between `Blob` and `ArrayBuffer` formats.**
|
||||
|
||||
That's set by `socket.bufferType` property, it's `"blob"` by default, so binary data comes as `Blob` objects.
|
||||
That's set by `socket.binaryType` property, it's `"blob"` by default, so binary data comes as `Blob` objects.
|
||||
|
||||
[Blob](info:blob) is a high-level binary object, it directly integrates with `<a>`, `<img>` and other tags, so that's a sane default. But for binary processing, to access individual data bytes, we can change it to `"arraybuffer"`:
|
||||
|
||||
```js
|
||||
socket.bufferType = "arraybuffer";
|
||||
socket.binaryType = "arraybuffer";
|
||||
socket.onmessage = (event) => {
|
||||
// event.data is either a string (if text) or arraybuffer (if binary)
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue