🌀 JS standard CRC-32 and CRC32C implementation https://cdn.sheetjs.com/crc-32/
Go to file
SheetJS 79a265b662 version bump 0.4.0
- added missing bitshift (fixes #5)
- brute-force unicode tests
2016-01-12 22:30:35 -05:00
bits version bump 0.4.0 2016-01-12 22:30:35 -05:00
ctest version bump 0.4.0 2016-01-12 22:30:35 -05:00
misc version bump 0.4.0 2016-01-12 22:30:35 -05:00
perf version bump 0.4.0 2016-01-12 22:30:35 -05:00
test_files version bump 0.4.0 2016-01-12 22:30:35 -05:00
.flowconfig version bump 0.3.0: cleanup and flow 2015-05-06 14:47:18 -07:00
.gitignore version bump 0.4.0 2016-01-12 22:30:35 -05:00
.jscs.json Initial commit 2014-06-16 17:27:47 -04:00
.jshintrc version bump 0.3.0: cleanup and flow 2015-05-06 14:47:18 -07:00
.npmignore version bump 0.4.0 2016-01-12 22:30:35 -05:00
.travis.yml version bump 0.4.0 2016-01-12 22:30:35 -05:00
crc32.flow.js version bump 0.4.0 2016-01-12 22:30:35 -05:00
crc32.js version bump 0.4.0 2016-01-12 22:30:35 -05:00
LICENSE version bump 0.4.0 2016-01-12 22:30:35 -05:00
Makefile version bump 0.4.0 2016-01-12 22:30:35 -05:00
package.json version bump 0.4.0 2016-01-12 22:30:35 -05:00
perf.txt version bump 0.2.0: performance 2014-06-17 19:20:41 -04:00
README.md version bump 0.4.0 2016-01-12 22:30:35 -05:00
test.js version bump 0.4.0 2016-01-12 22:30:35 -05:00

crc32

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

Installation

With npm:

$ npm install crc-32

In the browser:

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

The script will manipulate module.exports if available (e.g. in a CommonJS require context). This is not always desirable. To prevent the behavior, define DO_NOT_EXPORT_CRC

Usage

In all cases, the relevant function takes a single argument representing data.

The return value is a signed 32-bit integer.

  • CRC32.buf(byte array or buffer) assumes the argument is a set of 8-bit unsigned integers (e.g. nodejs Buffer or simple array of ints).

  • CRC32.bstr(binary string) interprets the argument as a binary string where the i-th byte is the low byte of the UCS-2 char: str.charCodeAt(i) & 0xFF

  • CRC32.str(string) interprets the argument as a standard JS string

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.str("\u2603"),  CRC32.str("\u0003")]   // [ -1743909036,  1259060791 ]
> [CRC32.bstr("\u2603"), CRC32.bstr("\u0003")]  // [  1259060791,  1259060791 ]
> [CRC32.buf([0x2603]),  CRC32.buf([0x0003])]   // [  1259060791,  1259060791 ]

Testing

make test will run the node-based tests.

To run the in-browser tests, run a local server and go to the ctest directory. To update the browser artifacts, run make ctest.

make baseline will generate baseline files based on the unicode mapping at http://mathias.html5.org

License

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.

Badges

Build Status

Coverage Status

Analytics