Gathering detailed insights and metrics for crc-32
Gathering detailed insights and metrics for crc-32
Gathering detailed insights and metrics for crc-32
Gathering detailed insights and metrics for crc-32
🌀 JS standard CRC-32 and CRC32C implementation
npm install crc-32
99.7
Supply Chain
100
Quality
76
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
346 Stars
42 Commits
37 Forks
10 Watching
1 Branches
6 Contributors
Updated on 07 Nov 2024
Minified
Minified + Gzipped
Python (60.55%)
JavaScript (39.43%)
CSS (0.01%)
Cumulative downloads
Total Downloads
Last day
-3.4%
1,931,643
Compared to previous day
Last week
4.2%
10,841,763
Compared to previous week
Last month
7%
45,119,955
Compared to previous month
Last year
28.3%
468,181,959
Compared to previous year
Standard CRC-32 algorithm implementation in JS (for the browser and nodejs). Emphasis on correctness, performance, and IE6+ support.
With a node package manager like npm
:
1$ npm i --save https://cdn.sheetjs.com/crc-32-latest/crc-32-latest.tgz
When installed globally, npm installs a script crc32
that computes the
checksum for a specified file or standard input.
Hosted versions are available at https://cdn.sheetjs.com/:
crc32.js
(CommonJS): https://cdn.sheetjs.com/crc-32-latest/package/crc32.jscrc32.mjs
(ESM): https://cdn.sheetjs.com/crc-32-latest/package/crc32.mjscrc32c.js
(CommonJS): https://cdn.sheetjs.com/crc-32-latest/package/crc32c.jscrc32c.mjs
(ESM): https://cdn.sheetjs.com/crc-32-latest/package/crc32c.mjsUsing NodeJS or a bundler with require
:
1var CRC32 = require("crc-32");
Using NodeJS or a bundler with import
:
1import { bstr, buf, str } from "crc-32";
In the browser, the crc32.js
script can be loaded directly:
1<script src="crc32.js"></script>
The browser script exposes a variable CRC32
.
The script will manipulate module.exports
if available . This is not always
desirable. To prevent the behavior, define DO_NOT_EXPORT_CRC
.
The module and CDNs also include a parallel script for CRC32C calculations.
Using NodeJS or a bundler:
1var CRC32C = require("crc-32/crc32c");
Using NodeJS or a bundler with import
:
1import { bstr, buf, str } from "crc-32/crc32c";
In the browser, the crc32c.js
script can be loaded directly:
1<script src="crc32c.js"></script>
The browser exposes a variable CRC32C
.
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:
1// var CRC32 = require('crc-32'); // uncomment this line if in node 2CRC32.str("SheetJS") // -1647298270 3CRC32.bstr("SheetJS") // -1647298270 4CRC32.buf([ 83, 104, 101, 101, 116, 74, 83 ]) // -1647298270 5 6crc32 = CRC32.buf([83, 104]) // -1826163454 "Sh" 7crc32 = CRC32.str("eet", crc32) // 1191034598 "Sheet" 8CRC32.bstr("JS", crc32) // -1647298270 "SheetJS" 9 10[CRC32.str("\u2603"), CRC32.str("\u0003")] // [ -1743909036, 1259060791 ] 11[CRC32.bstr("\u2603"), CRC32.bstr("\u0003")] // [ 1259060791, 1259060791 ] 12[CRC32.buf([0x2603]), CRC32.buf([0x0003])] // [ 1259060791, 1259060791 ] 13 14// var CRC32C = require('crc-32/crc32c'); // uncomment this line if in node 15CRC32C.str("SheetJS") // -284764294 16CRC32C.bstr("SheetJS") // -284764294 17CRC32C.buf([ 83, 104, 101, 101, 116, 74, 83 ]) // -284764294 18 19crc32c = CRC32C.buf([83, 104]) // -297065629 "Sh" 20crc32c = CRC32C.str("eet", crc32c) // 1241364256 "Sheet" 21CRC32C.bstr("JS", crc32c) // -284764294 "SheetJS" 22 23[CRC32C.str("\u2603"), CRC32C.str("\u0003")] // [ 1253703093, 1093509285 ] 24[CRC32C.bstr("\u2603"), CRC32C.bstr("\u0003")] // [ 1093509285, 1093509285 ] 25[CRC32C.buf([0x2603]), CRC32C.buf([0x0003])] // [ 1093509285, 1093509285 ]
Even though the initial seed is optional, for performance reasons it is highly recommended to explicitly pass the default seed 0.
In NodeJS with the native Buffer implementation, it is oftentimes faster to
convert binary strings with Buffer.from(bstr, "binary")
first:
1/* Frequently slower in NodeJS */
2crc32 = CRC32.bstr(bstr, 0);
3/* Frequently faster in NodeJS */
4crc32 = CRC32.buf(Buffer.from(bstr, "binary"), 0);
This does not apply to browser Buffer
shims, and thus is not implemented in
the library directly.
Unconventional for a CRC32 checksum, this library uses signed 32-bit integers. This is for performance reasons. Standard JS operators can convert between signed and unsigned 32-bit integers:
1CRC32.str("SheetJS") // -1647298270 (signed) 2CRC32.str("SheetJS") >>> 0 // 2647669026 (unsigned) 3(CRC32.str("SheetJS")>>>0).toString(16) // "9dd03922" (hex) 4 5(2647669026 | 0) // -1647298270
x >>> 0
converts a number value to unsigned 32-bit integer.
x | 0
converts a number value to signed 32-bit integer.
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
:
1>>> from zlib import crc32 2>>> x="foo bar baz٪☃🍣" 3>>> crc32(x) 41531648243 5>>> crc32(x+x) 6-218791105 7>>> crc32(x+x+x) 81834240887
The included crc32.njs
script can process files or standard input:
1$ echo "this is a test" > t.txt 2$ bin/crc32.njs t.txt 31912935186
For comparison, the included crc32.py
script uses python zlib
:
1$ bin/crc32.py t.txt 21912935186
On OSX the command cksum
generates unsigned CRC-32 with Algorithm 3:
1$ cksum -o 3 < IE8.Win7.For.Windows.VMware.zip 21891069052 4161613172 3$ crc32 --unsigned ~/Downloads/IE8.Win7.For.Windows.VMware.zip 41891069052
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.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Morecrc32
CRC-32 implemented in JavaScript
junderw-crc32c
Pure-JS CRC-32
js-crc
Simple CRC checksum functions for JavaScript. Supports many predefined models such as CRC-8, CRC-16, CRC-24, CRC-32, and CRC-64. It also supports custom CRC models.
polycrc
Fast Javascript calculation of custom CRC checksum. Prebuilt models for CRC-6, CRC-8, CRC-10, CRC-16, CRC-24, CRC-32, CRC-32C.