npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@foxglove/crc

v1.0.1

Published

Fast CRC32 computation in TypeScript

Downloads

21,747

Readme

@foxglove/crc

Fast CRC32 computation in TypeScript

npm version

Introduction

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.

Interface

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.

Usage

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);

Benchmarks

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

References

For further information about CRCs and their computation, see:

  • https://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks
  • https://github.com/komrad36/CRC
  • https://create.stephan-brumme.com/crc32/
  • https://zlib.net/crc_v3.txt
  • https://github.com/Michaelangel007/crc32
  • https://docs.microsoft.com/en-us/openspecs/office_protocols/ms-abs/06966aa2-70da-4bf9-8448-3355f277cd77

License

@foxglove/crc is licensed under the MIT License.

Releasing

  1. Run yarn version --[major|minor|patch] to bump version
  2. Run git push && git push --tags to push new tag
  3. GitHub Actions will take care of the rest

Stay in touch

Join our Slack channel to ask questions, share feedback, and stay up to date on what our team is working on.