magiclen / node-crc

To compute CRC values by providing the length of bits, expression, reflection, an initial value and a final xor value. It has many built-in CRC functions.
MIT License
31 stars 9 forks source link
crc nodejs rust

CRC For Node.js

CI

To compute CRC values by providing the length of bits, expression, reflection, an initial value and a final xor value. It has many built-in CRC functions.

You need to set up the Rust development environment: rustup

Usage

You can use crc function to compute a CRC value by providing the length of bits, expression, reflection, an initial value and a final xor value. For example, if you want to compute a CRC-24 value.

import { crc } from "node-crc";

const result = crc(0x00864cfb, 0x00000000, 24, 0x00b704ce, 0x00000000, 0x00000000, 0x00000000, false, Buffer.from("hello", "utf8")).toString("hex");
// Arguments: low bits of expression, high bits of expression, the length of bits, low bits of the initial value, high bits of the initial value, low bits of the final xor value, high bits of the final xor value, reflection, the source data buffer

To simplify the usage, there are several common versions of CRC whose computing functions are already built-in.

Input data and output data are buffers.

For instance,

import { crc32, crc64 } from "node-crc";

const result = crc32(Buffer.from("hello", "utf8")).toString("hex");
const result2 = crc64(Buffer.from("world", "utf8")).toString("hex");

TODO

  1. CRC class to compute large data

License

MIT