Javascript的ArrayBuffer或者TypedArrays没有任何类型的appendByte()、appendBytes()或者appendBuffer()方法。那么如果我想一次一个值地填充一个ArrayBuffer,我该怎么做呢?
var firstVal = 0xAB; // 1 byte
var secondVal = 0x3D7F // 2 bytes
var anotherUint8Array = someArr;
var buffer = new ArrayBuffer(); // I don't know the length yet
var bufferArr = new UInt8Array(buffer);
// following methods do not exist. What are the alternatives for each??
bufferArr.appendByte(firstVal);
bufferArr.appendBytes(secondVal);
bufferArr.appendBuffer(anotherUint8Array);
r[i]=x
,例如:https://github.com/rndme/download/blob/master/download.js#L69。同时请查看Uint8Array构造函数的语法:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array#Syntax - 你需要在数组缓冲区中指定大小才能像那样使用它... - dandavis