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
你創建後無法修改緩衝區大小 –