Update article.md

This commit is contained in:
Ilya Kantor 2020-08-03 08:15:53 +03:00 committed by GitHub
parent cdf382de4c
commit 0f391b2e2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)
};