Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@foxglove/crc
Advanced tools
Fast CRC32 computation in TypeScript
A Cyclic Redundancy Check (CRC) is a calculation used to detect errors in data transmission.
This library implements CRC32, the standard 32-bit CRC using the binary polynomial 0xEDB88320
. This is the same algorithm used in PNG, zlib, and other popular applications.
The following functions are exported from this package:
function crc32Init(): number;
function crc32Update(prev: number, data: ArrayBufferView): number;
function crc32Final(prev: number): number;
function crc32(data: ArrayBufferView): number;
Note: Since the CRC algorithm works with unsigned data, the crc32
and crc32Final
functions always return non-negative numbers. For example, CRC32(0x01) returns 2768625435 rather than -1526341861.
import { crc32 } from "@foxglove/crc";
const data = new Uint8Array(...);
const crc = crc32(data);
import { crc32Init, crc32Update, crc32Final } from "@foxglove/crc";
let crc = crc32Init();
while (/* more data available */) {
crc = crc32Update(crc, data);
}
crc = crc32Final(crc);
This package achieves a >5x performance improvement over many other CRC packages, because of the multi-byte algorithms used (adapted from https://github.com/komrad36/CRC).
The following benchmarks were recorded on a MacBook Pro with an M1 Pro chip and 16GB of RAM. Each iteration ("op") is processing 1MB of data.
$ yarn bench
...
crc:
355 ops/s, ±0.56% | 81.52% slower
node-crc:
376 ops/s, ±0.14% | 80.43% slower
crc-32:
1 057 ops/s, ±0.16% | 44.98% slower
polycrc:
327 ops/s, ±0.21% | slowest, 82.98% slower
this package:
1 921 ops/s, ±0.18% | fastest
For further information about CRCs and their computation, see:
@foxglove/crc is licensed under the MIT License.
yarn version --[major|minor|patch]
to bump versiongit push && git push --tags
to push new tagJoin our Slack channel to ask questions, share feedback, and stay up to date on what our team is working on.
FAQs
Fast CRC32 computation in TypeScript
We found that @foxglove/crc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.