A high-performance, dependency-free library for calculating CRC32 and CRC32C checksums in TypeScript.
npm install @se-oss/crc32


!npm bundle size

_@se-oss/crc32_ is a high-performance, dependency-free TypeScript library for calculating CRC32 and CRC32C checksums for strings, Buffers, and Uint8Arrays, with optional hardware acceleration for CRC32C.
---
- Installation
- Usage
- Documentation
- Performance
- Contributing
- License
``bash`
npm install @se-oss/crc32
Install using your favorite package manager
pnpm
`bash`
pnpm install @se-oss/crc32
yarn
`bash`
yarn add @se-oss/crc32
Calculates the CRC32 checksum of a value.
`ts
import { crc32 } from '@se-oss/crc32';
// Calculate CRC32 checksum for a string
const text = 'hello world';
const checksum = crc32(text); // 222957957
// Calculate CRC32 checksum for a Buffer
const buffer = Buffer.from(text);
const bufferChecksum = crc32(buffer); // 222957957
// Calculate CRC32 checksum for a Uint8Array
const uint8Array = new TextEncoder().encode(text);
const uint8ArrayChecksum = crc32(uint8Array); // 222957957
// Incremental calculation using a seed
const part1 = 'hello';
const part2 = ' world';
const whole = 'hello world';
const seed = crc32(part1);
const finalChecksum = crc32(part2, seed);
console.log(finalChecksum === crc32(whole)); // true
`
Calculates the CRC32C checksum of a value. This function will automatically use the hardware-accelerated version if the sse4_crc32 package is available.
`ts
import { crc32c } from '@se-oss/crc32';
// Calculate CRC32C checksum for a string
const text = 'hello world';
const checksum = crc32c(text); // 3381945770
// Calculate CRC32C checksum for a Buffer
const buffer = Buffer.from(text);
const bufferChecksum = crc32c(buffer); // 3381945770
// Calculate CRC32C checksum for a Uint8Array
const uint8Array = new TextEncoder().encode(text);
const uint8ArrayChecksum = crc32c(uint8Array); // 3381945770
// Incremental calculation using a seed
const part1 = 'hello';
const part2 = ' world';
const whole = 'hello world';
const seed = crc32c(part1);
const finalChecksum = crc32c(part2, seed);
console.log(finalChecksum === crc32c(whole)); // true
`
For all configuration options, please see the API docs.
| Library | small buffer (100B) | medium buffer (1KB) | large buffer (100KB) |
| ----------------- | -------------------- | ------------------- | -------------------- |
| @se-oss/crc32 | _10,185,250 ops/sec_ | _1,686,718 ops/sec_ | _18,800 ops/sec_ |
| crc-32 | 5,652,118 ops/sec | 1,485,637 ops/sec | 18,249 ops/sec |
| Library | small buffer (100B) | medium buffer (1KB) | large buffer (100KB) |
| ----------------- | ------------------- | ------------------- | -------------------- |
| @se-oss/crc32 | _9,983,748 ops/sec_ | _1,823,301 ops/sec_ | _19,928 ops/sec_ |
| crc-32/crc32c | 5,300,129 ops/sec | 1,648,967 ops/sec | 19,129 ops/sec |
| fast-crc32c | 3,374,422 ops/sec | 508,594 ops/sec | 4,973 ops/sec |
_Benchmark script: src/index.bench.ts`_
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub
Thanks again for your support, it is much appreciated! 🙏
MIT © Shahrad Elahi and contributors.