You can use a DataView object to read and write the different kinds of binary data to any location in the ArrayBuffer.
SyntaxdataView = new DataView( DataView( buffer , byteOffset , byteLength ));
The following example shows how to use a DataView object to process the binary data acquired from an XmlHttpRequest:
var req = new XMLHttpRequest();
req.open('GET', "http://www.example.com");
req.responseType = "arraybuffer";
req.send();
req.onreadystatechange = function () {
if (req.readyState === 4) {
var buffer = req.response;
var dataView = new DataView(buffer);
var ints = new Int32Array(dataView.byteLength / 4);
for (var i = 0; i < ints.length; i++) {
ints[i] = dataview.getInt32(i * 4);
}
alert(ints[10]);
}
}
Remarks
If both byteOffset and byteLength are omitted, the DataView spans the entire ArrayBuffer range. If the byteLength is omitted, the DataView extends from the given byteOffset until the end of the ArrayBuffer. If the given byteOffset and byteLength references an area beyond the end of the ArrayBuffer, an exception is raised.
PropertiesThe following table lists the properties of the DataView object.
Property Description buffer Property Read-only. Gets the ArrayBuffer that is referenced by this view. byteLength Property Read-only. The length of this view from the start of its ArrayBuffer, in bytes, as fixed at construction time. byteOffset Property Read-only. The offset of this view from the start of its ArrayBuffer, in bytes, as fixed at construction time. MethodsThe following table lists the methods of the DataView object.
AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4