fast-crc32c
Hardware-accelerated CRC-32C checksums for Node.js with an automatic pure-JavaScript fallback.
Repository Health
Technical Analysis
fast-crc32c computes CRC-32C checksums — the variant of CRC-32 used by protocols and formats like iSCSI, SCTP, and Btrfs — in Node.js applications. It first attempts to use a native SSE4.2 hardware-accelerated implementation via the optional sse4_crc32 dependency, verifying its output against a known test vector before trusting it, and transparently falls back to a pure JavaScript, table-driven implementation if the native binding isn’t available or fails to compile.
The library exposes a single function, calculate(data, initial), that behaves identically regardless of which backend served the computation, so consuming code never needs to know or care whether hardware acceleration is active.
What You Get
- A single calculate(data, initial) function for computing CRC-32C digests of strings or Buffers
- Automatic hardware acceleration via the optional sse4_crc32 native binding when it’s installed and working
- A pure JavaScript, table-driven CRC-32C fallback that runs anywhere Node.js runs, no native compile required
- Built-in self-verification that checks the native backend’s output against a known test vector before trusting it
Common Use Cases
- Validating data integrity for storage formats that specify CRC-32C, such as iSCSI, SCTP, and Btrfs
- Computing rolling checksums for chunked uploads or downloads to detect corruption
- Deduplicating or fingerprinting data blocks in backup and sync tools
Under The Hood
Architecture loader.js implements a simple strategy-selection pattern executed once at require time: it tries impls/sse4_crc32c.js (a thin wrapper around the optional native sse4_crc32 binding) first, computes a known test string’s digest, and only accepts that backend if the result matches the expected value; on any failure it falls through to impls/js_crc32c.js. The chosen implementation’s calculate function is memoized as the module’s export, so the selection cost is paid once per process rather than per call.
Tech Stack The package is plain JavaScript with no build step of its own; its only meaningful dependency is the optional native addon sse4_crc32, which requires a native compile toolchain to install and is skipped gracefully when unavailable. Tests run on mocha with nyc for coverage and a coveralls integration, fixtures are generated programmatically by generate-tests.js from a checked-in sets.json, and dependencies are locked via yarn.lock.
Code Quality test/crc32c.js runs the same generated fixture cases against both the pure JavaScript implementation directly and the public export, exercising whichever backend loader.js selected. There is no TypeScript, no visible linter configuration, and the CI setup is a Travis config that predates the repo’s last commit in December 2022 — the project has been inactive for several years with a backlog of open issues.
API Design The entire public surface is one function, calculate(data, initial), that is agnostic to which backend produced the result — callers get a hardware speed boost automatically whenever the native dependency installs successfully, with no configuration, feature flags, or fallback logic to write themselves. The optional initial parameter lets callers chain digests across chunks without any additional API surface.