For example, I requested a piece of binary data 0001001000111100 through the XMLHttpRequest() method
var oReq = new XMLHttpRequest();
oReq.responseType = "arraybuffer";
var resp = oReq.open("GET",url,true)
oReq.onload = function (oEvent) {
var arrayBuffer = oReq.response;
}
So how do I operate this Arraybuffer? I know that the corresponding array can be obtained through different views
such as
var responseArray = new Uint8Array(arrayBuffer);
console.log(responseArray)
//输出Uint8Array(2) [18, 60]
So when this arraybuffer is very, very large, what should you do if you want to extract the information in it? After the 4mb arraybuffer
is output through Uint8Array, the array will also have a length of 410001000/8 = 500,000. .
For example, I want to fill in data to certain locations in arraybuffer. . So what should be done?
Wouldn’t it be possible to use a view like Uint8Array to construct a new array?
arraybuffer cannot be operated directly and can only be accessed through DataView or typedArray. If you need to modify certain bits of data, you must first know the offset of the data relative to the arrayBuffer, through dataview.setInt8(byteOffset, value); or typedArray[. .] to modify.