5

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?

0

2 Answers 2

2

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]
Sign up to request clarification or add additional context in comments.

4 Comments

Websocket can only send ArrayBuffer not Uint8Array or others
@Demion: I know, the input and output is an ArrayBuffer here (origBuffer and buffer).
@konga raju: Thanks for the heads up!
But slice produce new Array. This is not GC-Friendly. Does anyone knows better way?
0

Read these articles the specification was changed.

http://www.html5rocks.com/en/tutorials/webgl/typed_arrays/

http://updates.html5rocks.com/2012/06/How-to-convert-ArrayBuffer-to-and-from-String

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.