const TABLE = buildTable(); function buildTable(): Uint32Array { const table = new Uint32Array(256); for (let n = 0; n < 256; n++) { let c = n; for (let k = 0; k < 8; k++) { c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; } table[n] = c >>> 0; } return table; } /** CRC32 of `bytes`, as required by the PNG chunk format (ISO 3309 / ITU-T V.42). */ export function crc32(bytes: Uint8Array): number { let crc = 0xffffffff; for (let i = 0; i < bytes.length; i++) { const byte = bytes[i]!; crc = TABLE[(crc ^ byte) & 0xff]! ^ (crc >>> 8); } return (crc ^ 0xffffffff) >>> 0; }