@@ -1,25 +1,17 @@
|
||||
const table = (() => {
|
||||
const values = new Uint32Array(256);
|
||||
for (let index = 0; index < values.length; index += 1) {
|
||||
let value = index;
|
||||
for (let bit = 0; bit < 8; bit += 1)
|
||||
value = value & 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;
|
||||
values[index] = value >>> 0;
|
||||
}
|
||||
return values;
|
||||
})();
|
||||
import {
|
||||
crc32 as sharedCrc32,
|
||||
formatChecksum,
|
||||
} from "@add-ideas/toolbox-helpers";
|
||||
import { ARCHIVE_LIMITS } from "./limits";
|
||||
|
||||
export function crc32(bytes: Uint8Array): number {
|
||||
let value = 0xffffffff;
|
||||
for (const byte of bytes)
|
||||
value = table[(value ^ byte) & 0xff]! ^ (value >>> 8);
|
||||
return (value ^ 0xffffffff) >>> 0;
|
||||
return sharedCrc32(bytes, ARCHIVE_LIMITS.maxExpandedBytes);
|
||||
}
|
||||
|
||||
export function crc32Hex(bytes: Uint8Array): string {
|
||||
return crc32(bytes).toString(16).padStart(8, "0");
|
||||
return formatChecksum(crc32(bytes));
|
||||
}
|
||||
|
||||
export function uint32Hex(value: number): string {
|
||||
return (value >>> 0).toString(16).padStart(8, "0");
|
||||
return formatChecksum(value >>> 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user