You cannot compare two objects directly in JavaScript using ==
or ===
.
These operators will only check the equality of references (i.e. if expressions reference the same object).
You can, however, use DataView
or ArrayView
objects to retrieve values of specific parts of ArrayBuffer
objects and check them.
If you want to check headers:
if ( view1.getUint8 (0) == view2.getUint8 (0)
&& view1.getUint16(2) == view2.getUint16(2)) ...
Or if you want to check the globality of your buffers:
function equal (buf1, buf2)
{
if (buf1.byteLength != buf2.byteLength) return false;
var dv1 = new Int8Array(buf1);
var dv2 = new Int8Array(buf2);
for (var i = 0 ; i != buf1.byteLength ; i++)
{
if (dv1[i] != dv2[i]) return false;
}
return true;
}
If you want to implement a complex data structure based on ArrayBuffer
, I suggest creating your own class, or else you will have to resort to cumbersome raw DataView
/ ArrayView
instances each time you will want to move a matchstick in and out of the structure.