Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cyclic-32

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cyclic-32

Tiny, streaming, seedable CRC32 library, compatible with the crypto.Hash API

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.3K
increased by35.11%
Maintainers
1
Weekly downloads
 
Created
Source

cyclic-32

npm npm license npm downloads

A tiny, streaming, seedable CRC32 library, compatible with Node's crypto.Hash API. In less than 100 LOC.

Install via npm

$ npm install --save cyclic-32

Features

  • Speed: ~300 MB/s on a 2012 Macbook Air
  • Size: It's 96 lines of code (plus 22 lines of comments, and 17 blank)
  • Streams: .pipe().pipe().pipe()
  • Seedable: If you have more complex things in mind
  • CLI: Possibly useful for npm run scripts

Usage

API

var checksum = crc32( buffer, seed = 0, table = crc32.TABLE.DEFAULT )
// Shorthand for Castagnoli
var castagnoli = crc32.c( buffer, seed = 0, table = crc32.TABLE.DEFAULT )
var checksumStream = crc32.createHash({
  seed: 0,
  table: crc32.TABLE.DEFAULT,
})

Builtin tables:

  • crc32.TABLE.DEFAULT: Standard CRC32
  • crc32.TABLE.CASTAGNOLI: Castagnoli

Examples

var crc32 = require( 'cyclic-32' )

Calculate the CRC32 checksum of a Buffer:

var buffer = new Buffer( 'I shall be summed', 'ascii' )
console.log( crc32( buffer ) ) // -476443423

Pass a seed value:

var buffer = new Buffer( 'I shall be summoned', 'ascii' )
console.log( crc32( buffer, 666 ) ) // -823676065

Calculate the CRC32 checksum over a Stream:

fs.createReadStream( filename )
  .pipe( crc32.createHash() )
  .on( 'data', function( buffer ) {
    console.log( 'CRC32:', buffer.toString( 'hex' ) )
  })

If you want to pass an encoding, or seed:

fs.createReadStream( filename )
  .pipe( new crc32.Hash({ encoding: 'hex', seed: -12345678 }) )
  .on( 'data', function( checksum ) {
    console.log( 'CRC32:', checksum )
  })

Or, if you'd rather stick to the crypto.Hash API:

var hash = crc32.createHash()

hash.update( 'I shall' )
  .update( 'be summed' )

console.log( 'CRC32:', hash.digest( 'hex' ) )

CLI Usage

Calculate the checksum of a file:

$ crc32 filename
0a0ca5aa

Pipe stuff into it via stdin:

$ cat filename | crc32
ffe6bbc0

Keywords

FAQs

Package last updated on 19 Sep 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc