I am comparing two Uint8Array
using CRC32 to ensure the accuracy of the data being decompressed. However, I am facing the issue of not having an API like Uint8Array.equal()
to compare the arrays. Although there is Buffer.compare()
available in Node.js, it is not supported in the browser, which I am also working on.
I have created a basic implementation, but I am unsure if there is a more straightforward approach or if I have overlooked any built-in comparison APIs.
function isEqual(arr1: Uint8Array, arr2: Uint8Array): boolean {
if (arr1.length !== arr2.length) {
return false
}
return arr1.every((value, index) => value === arr2[index])
}
.prototype.compare
implementation here – Mimicryevery
. – BillitonBuffer.compare
API. – Copolymerize