package
Tiny, streaming, seedable CRC32 library, compatible with the crypto.Hash API
npm install cyclic-32GitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
14.8 kB
Includes dependencies.
A tiny, streaming, seedable CRC32 library, compatible with Node's crypto.Hash API. In less than 100 LOC.
$ npm install --save cyclic-32var 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 CRC32crc32.TABLE.CASTAGNOLI: Castagnolivar crc32 = require( 'cyclic-32' )Calculate the CRC32 checksum of a Buffer:
var buffer = new Buffer( 'I shall be summed', 'ascii' )
console.log( crc32( buffer ) ) // -476443423Pass a seed value:
var buffer = new Buffer( 'I shall be summoned', 'ascii' )
console.log( crc32( buffer, 666 ) ) // -823676065Calculate 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' ) )Calculate the checksum of a file:
$ crc32 filename
0a0ca5aaPipe stuff into it via stdin:
$ cat filename | crc32
ffe6bbc0