mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
21 lines
512 B
TypeScript
21 lines
512 B
TypeScript
export default function removeNonSignificantZeroBytes(bytes: Uint8Array) {
|
|
return shouldRemoveBytes(bytes) ? bytes.filter((item, index) => index % 32) : bytes;
|
|
}
|
|
|
|
// check if every 0, 32, 64, etc byte is 0 in the provided array
|
|
function shouldRemoveBytes(bytes: Uint8Array) {
|
|
let result = true;
|
|
|
|
for (let index = 0; index < bytes.length; index += 32) {
|
|
const element = bytes[index];
|
|
if (element === 0) {
|
|
continue;
|
|
} else {
|
|
result = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|