Javascript ArrayBuffer hoặc TypedArrays không có bất kỳ loại phương thức appendByte(), appendBytes() hoặc appendBuffer() nào. Vì vậy, nếu tôi muốn điền vào một ArrayBuffer một giá trị tại một thời điểm, làm thế nào để làm điều đó?Làm cách nào để chắp thêm byte, nhiều byte và bộ đệm vào ArrayBuffer trong javascript?
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);
là một mảng, sử dụng cú pháp mảng 'r [i] = x' ví dụ: https://github.com/rndme/download/blob/master/download.js#L69 cũng xem lại cú pháp cho hàm tạo Uint8Array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array#Syntax - bạn cần kích thước trên bộ đệm mảng đó để có thể sử dụng nó như vậy .... – dandavis
Bạn không thể sửa đổi kích thước bộ đệm sau khi nó được tạo ra –