Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websocket binary data messages (ArrayBuffer)

As I understand ArrayBuffer length is set only by constructor and cannot be changed dynamically. So I am curious, is it possible using websockets binary data messages send arraybuffer certain part, not whole buffer?

like image 910
Demion Avatar asked Nov 05 '22 09:11

Demion


1 Answers

You can use .slice to slice an ArrayBuffer: http://jsfiddle.net/rtaB4/21/.

var inputBuffer = new Uint8Array([0, 1, 2, 3, 4]).buffer;
var outputBuffer = inputBuffer.slice(1, 3);

console.log(outputBuffer.byteLength);       // 2
console.log(new Uint8Array(outputBuffer));  // [1, 2]
like image 127
pimvdb Avatar answered Nov 14 '22 23:11

pimvdb