Skip to content
/ crc Public

CRC functions with a parameterized engine optimized for both speed and size

License

Notifications You must be signed in to change notification settings

hqtsm/crc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3847c5d · Dec 17, 2024

History

60 Commits
Dec 17, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Dec 15, 2024
Nov 2, 2024
Nov 2, 2024
Nov 2, 2024
Nov 19, 2024
Nov 2, 2024
Nov 20, 2024
Dec 15, 2024
Dec 7, 2024
Dec 7, 2024
Nov 2, 2024
Dec 7, 2024

Repository files navigation

HQTSM: CRC

CRC functions with a parameterized engine optimized for both speed and size

crc digest checksum hash typescript esm streamable crc-8 crc-16 crc-24 crc-32 crc-64

JSR npm CI

Features

  • Pure TypeScript, run anywhere
  • Optimized for speed
    • Table-based algorithm
    • Minimal initialization code
  • Optimized for size
    • Shared engine < 500 bytes with standard web compression
    • Tables generated on first use
    • Minimal additional overhead to each variant
    • Individually importable algorithms
  • 100+ known digests provided, plus the option of configuring your own
  • Streamable interface, just call update for each chunk
  • Number for small digests, 32-bit or less
  • BigInt for larger digests
  • Digest values always an unsigned integer
  • Supports 8-bit typed arrays, regular arrays, and array-like objects
  • Pure methods, can be assigned directly to variables as needed

Usage

CRC-32/ISO-HDLC

The most-common 32-bit digest, used by PNG, ZIP, and more.

import CRC32 from '@hqtsm/crc/crc-32/iso-hdlc';

let crc = CRC32.init();
crc = CRC32.update(crc, new TextEncoder().encode('123456789'));
crc = CRC32.finalize(crc);
console.assert(crc.toString(16) === 'cbf43926');

CRC-64/XZ

A common 64-bit digest, sometimes incorrectly refered to as ECMA-182.

import CRC64 from '@hqtsm/crc/crc-64/xz';

let crc = CRC64.init();
crc = CRC64.update(crc, new TextEncoder().encode('123456789'));
crc = CRC64.finalize(crc);
console.assert(crc.toString(16) === '995dc9bbdf1939fa');

Acknowledgements

Thanks to pycrc for the inspiration and validation checking.

Thanks to CRC RevEng for cataloging the different digests.