Socket
Socket
Sign inDemoInstall

buffer-crc32

Package Overview
Dependencies
0
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

buffer-crc32

A pure javascript CRC32 algorithm that plays nice with binary data

    1.0.0latest
    GitHub
    npm

Version published
Maintainers
2
Weekly downloads
19,930,051
increased by5.97%

Weekly downloads

Readme

Source

buffer-crc32

NPM Version Build Status

crc32 that works with binary data and fancy character sets, outputs buffer, signed or unsigned data and has tests.

Derived from the sample CRC implementation in the PNG specification: http://www.w3.org/TR/PNG/#D-CRCAppendix

This package requires Node 8+ to work.

install

npm install buffer-crc32

example

const crc32 = require('buffer-crc32');
// works with buffers
const buf = Buffer([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00]);
crc32(buf); // -> <Buffer 94 5a ab 4a>

// has convenience methods for getting signed or unsigned ints
crc32.signed(buf); // -> -1805997238
crc32.unsigned(buf); // -> 2488970058

// will cast to buffer if given a string, so you can
// directly use foreign characters safely
crc32('自動販売機'); // -> <Buffer cb 03 1a c5>

// and works in append mode too
const partialCrc = crc32('hey');
const partialCrc = crc32(' ', partialCrc);
const partialCrc = crc32('sup', partialCrc);
const partialCrc = crc32(' ', partialCrc);
const finalCrc = crc32('bros', partialCrc); // -> <Buffer 47 fa 55 70>

tests

This was tested against the output of zlib's crc32 method. You can run the tests withnpm test (requires tap)

see also

https://github.com/alexgorbatchev/node-crc, crc.buffer.crc32 also supports buffer inputs and return unsigned ints (thanks @tjholowaychuk).

license

MIT/X11

FAQs

Last updated on 06 Feb 2024

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc