meshcore.js/src/buffer_utils.js

37 lines
804 B
JavaScript
Raw Normal View History

class BufferUtils {
2025-03-10 14:05:05 +13:00
static bytesToHex(uint8Array) {
return Array.from(uint8Array).map(byte => {
return byte.toString(16).padStart(2, '0');
}).join('');
}
2025-03-11 20:23:25 +13:00
static base64ToBytes(base64) {
return Uint8Array.from(atob(base64), (c) => {
return c.charCodeAt(0);
});
}
static areBuffersEqual(byteArray1, byteArray2) {
// ensure length is the same
if(byteArray1.length !== byteArray2.length){
return false;
}
// ensure each item is the same
for(let i = 0; i < byteArray1.length; i++){
if(byteArray1[i] !== byteArray2[i]){
return false;
}
}
// arrays are the same
return true;
}
}
export default BufferUtils;