Javascript ArrayBuffer或TypedArrays没有任何类型的appendByte(),appendBytes()或appendBuffer()方法。所以如果我想一次填充一个ArrayBuffer的一个值,我该怎么做?如何将字节,多字节和缓冲区添加到JavaScript中的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
你创建后无法修改缓冲区大小 –