Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Standard CRC-32 algorithm implementation in JS (for the browser and nodejs). Emphasis on correctness, performance, and IE6+ support.


With npm:

$ npm install crc-32

In the browser:

<script src="crc32.js"></script>

The browser exposes a variable CRC32.

When installed globally, npm installs a script crc32 that computes the checksum for a specified file or standard input.

The script will manipulate module.exports if available . This is not always desirable. To prevent the behavior, define DO_NOT_EXPORT_CRC.


In all cases, the relevant function takes an argument representing data and an optional second argument representing the starting "seed" (for rolling CRC).

The return value is a signed 32-bit integer.

  • CRC32.buf(byte array or buffer[, seed]) assumes the argument is a sequence of 8-bit unsigned integers (nodejs Buffer, Uint8Array or array of bytes).

  • CRC32.bstr(binary string[, seed]) assumes the argument is a binary string where byte i is the low byte of the UCS-2 char: str.charCodeAt(i) & 0xFF

  • CRC32.str(string[, seed]) assumes the argument is a standard JS string and calculates the hash of the UTF-8 encoding.

For example:

// var CRC32 = require('crc-32');             // uncomment this line if in node
CRC32.str("SheetJS")                          // -1647298270
CRC32.bstr("SheetJS")                         // -1647298270
CRC32.buf([ 83, 104, 101, 101, 116, 74, 83 ]) // -1647298270

crc32 = CRC32.buf([83, 104])                  // -1826163454  "Sh"
crc32 = CRC32.str("eet", crc32)               //  1191034598  "Sheet"
CRC32.bstr("JS", crc32)                       // -1647298270  "SheetJS"

[CRC32.str("\u2603"),  CRC32.str("\u0003")]   // [ -1743909036,  1259060791 ]
[CRC32.bstr("\u2603"), CRC32.bstr("\u0003")]  // [  1259060791,  1259060791 ]
[CRC32.buf([0x2603]),  CRC32.buf([0x0003])]   // [  1259060791,  1259060791 ]


make test will run the nodejs-based test.

To run the in-browser tests, run a local server and go to the ctest directory. make ctestserv will start a python SimpleHTTPServer server on port 8000.

To update the browser artifacts, run make ctest.

To generate the bits file, use the crc32 function from python zlib:

>>> from zlib import crc32
>>> x="foo bar baz٪☃🍣"
>>> crc32(x)
>>> crc32(x+x)
>>> crc32(x+x+x)

The included crc32.njs script can process files or standard input:

$ echo "this is a test" > t.txt
$ bin/crc32.njs t.txt

For comparison, the included script uses python zlib:

$ bin/ t.txt

On OSX the command cksum generates unsigned CRC-32 with Algorithm 3:

$ cksum -o 3 <
1891069052 4161613172
$ crc32 --unsigned ~/Downloads/


make perf will run algorithmic performance tests (which should justify certain decisions in the code).

The adler-32 project has more performance notes


Please consult the attached LICENSE file for details. All rights not explicitly granted by the Apache 2.0 license are reserved by the Original Author.


Sauce Test Status

Build Status Coverage Status Dependencies Status NPM Downloads Analytics

You can’t perform that action at this time.