(crc: number, bytes: Uint8Array)
| 858 | const littleEndian = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1 |
| 859 | |
| 860 | const crc32 = (crc: number, bytes: Uint8Array): number => { |
| 861 | const t = CRC_TABLE |
| 862 | let c = ~crc |
| 863 | let i = 0 |
| 864 | const length = bytes.length |
| 865 | // Reading whole words is faster than combining bytes, but needs aligned, |
| 866 | // little-endian words |
| 867 | if (littleEndian && length >= 64) { |
| 868 | for (; ((bytes.byteOffset + i) & 3) !== 0; i++) c = t[(c ^ bytes[i]) & 0xff] ^ (c >>> 8) |
| 869 | const count = ((length - i) >>> 4) << 2 |
| 870 | const words = new Int32Array(bytes.buffer, bytes.byteOffset + i, count) |
| 871 | for (let j = 0; j < count; j += 4) { |
| 872 | const a = c ^ words[j] |
| 873 | const b = words[j + 1] |
| 874 | const d = words[j + 2] |
| 875 | const e = words[j + 3] |
| 876 | c = t[3840 + (a & 0xff)] ^ t[3584 + ((a >>> 8) & 0xff)] ^ t[3328 + ((a >>> 16) & 0xff)] ^ |
| 877 | t[3072 + (a >>> 24)] ^ t[2816 + (b & 0xff)] ^ t[2560 + ((b >>> 8) & 0xff)] ^ |
| 878 | t[2304 + ((b >>> 16) & 0xff)] ^ t[2048 + (b >>> 24)] ^ t[1792 + (d & 0xff)] ^ |
| 879 | t[1536 + ((d >>> 8) & 0xff)] ^ t[1280 + ((d >>> 16) & 0xff)] ^ t[1024 + (d >>> 24)] ^ |
| 880 | t[768 + (e & 0xff)] ^ t[512 + ((e >>> 8) & 0xff)] ^ t[256 + ((e >>> 16) & 0xff)] ^ t[e >>> 24] |
| 881 | } |
| 882 | i += count * 4 |
| 883 | } |
| 884 | for (; i + 16 <= length; i += 16) { |
| 885 | const a = c ^ (bytes[i] | (bytes[i + 1] << 8) | (bytes[i + 2] << 16) | (bytes[i + 3] << 24)) |
| 886 | c = t[3840 + (a & 0xff)] ^ t[3584 + ((a >>> 8) & 0xff)] ^ t[3328 + ((a >>> 16) & 0xff)] ^ |
| 887 | t[3072 + (a >>> 24)] ^ t[2816 + bytes[i + 4]] ^ t[2560 + bytes[i + 5]] ^ t[2304 + bytes[i + 6]] ^ |
| 888 | t[2048 + bytes[i + 7]] ^ t[1792 + bytes[i + 8]] ^ t[1536 + bytes[i + 9]] ^ t[1280 + bytes[i + 10]] ^ |
| 889 | t[1024 + bytes[i + 11]] ^ t[768 + bytes[i + 12]] ^ t[512 + bytes[i + 13]] ^ t[256 + bytes[i + 14]] ^ |
| 890 | t[bytes[i + 15]] |
| 891 | } |
| 892 | for (; i < length; i++) c = t[(c ^ bytes[i]) & 0xff] ^ (c >>> 8) |
| 893 | return ~c >>> 0 |
| 894 | } |
| 895 | |
| 896 | const validate = (header: Header): void => { |
| 897 | const { method, mode, mtime, path, size, type } = header |
no outgoing calls
no test coverage detected