formats.exposed/public/common/bytes.js

29 lines
584 B
JavaScript
Raw Normal View History

// @ts-check
/**
* @param {Uint8Array} a
* @param {Uint8Array} b
* @returns {boolean}
*/
export const areBytesEqual = (a, b) => {
if (a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) return false;
}
return true;
};
/**
* @param {Uint8Array} bytes
* @param {number} size
* @returns {Uint8Array[]}
*/
export const chunkBytes = (bytes, size) => {
/** @type {Uint8Array[]} */
const result = [];
for (let i = 0; i < bytes.byteLength; i += size) {
result.push(bytes.subarray(i, i + size));
}
return result;
};