{"id":13692945,"url":"https://github.com/SheetJS/js-crc32","last_synced_at":"2025-05-02T20:30:23.259Z","repository":{"id":383980,"uuid":"20901220","full_name":"SheetJS/js-crc32","owner":"SheetJS","description":":cyclone: JS standard CRC-32 and CRC32C implementation","archived":false,"fork":false,"pushed_at":"2022-08-20T21:32:00.000Z","size":22367,"stargazers_count":346,"open_issues_count":2,"forks_count":37,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-29T22:02:15.225Z","etag":null,"topics":["bytes","checksum","crc","crc-32","crc32c","data"],"latest_commit_sha":null,"homepage":"http://oss.sheetjs.com/js-crc32/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SheetJS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-16T21:21:27.000Z","updated_at":"2025-02-24T19:12:54.000Z","dependencies_parsed_at":"2022-08-06T09:15:05.552Z","dependency_job_id":null,"html_url":"https://github.com/SheetJS/js-crc32","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SheetJS%2Fjs-crc32","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SheetJS%2Fjs-crc32/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SheetJS%2Fjs-crc32/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SheetJS%2Fjs-crc32/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SheetJS","download_url":"https://codeload.github.com/SheetJS/js-crc32/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251825348,"owners_count":21649939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytes","checksum","crc","crc-32","crc32c","data"],"created_at":"2024-08-02T17:01:03.783Z","updated_at":"2025-05-02T20:30:23.191Z","avatar_url":"https://github.com/SheetJS.png","language":"Python","readme":"# crc32\n\nStandard CRC-32 algorithm implementation in JS (for the browser and nodejs).\nEmphasis on correctness, performance, and IE6+ support.\n\n## Installation\n\nWith a node package manager like `npm`:\n\n```bash\n$ npm i --save https://cdn.sheetjs.com/crc-32-latest/crc-32-latest.tgz\n```\n\nWhen installed globally, npm installs a script `crc32` that computes the\nchecksum for a specified file or standard input.\n\nHosted versions are available at \u003chttps://cdn.sheetjs.com/\u003e:\n\n- `crc32.js` (CommonJS): \u003chttps://cdn.sheetjs.com/crc-32-latest/package/crc32.js\u003e\n- `crc32.mjs` (ESM): \u003chttps://cdn.sheetjs.com/crc-32-latest/package/crc32.mjs\u003e\n- `crc32c.js` (CommonJS): \u003chttps://cdn.sheetjs.com/crc-32-latest/package/crc32c.js\u003e\n- `crc32c.mjs` (ESM): \u003chttps://cdn.sheetjs.com/crc-32-latest/package/crc32c.mjs\u003e\n\n## Integration\n\nUsing NodeJS or a bundler with `require`:\n\n```js\nvar CRC32 = require(\"crc-32\");\n```\n\nUsing NodeJS or a bundler with `import`:\n\n```js\nimport { bstr, buf, str } from \"crc-32\";\n```\n\nIn the browser, the `crc32.js` script can be loaded directly:\n\n```html\n\u003cscript src=\"crc32.js\"\u003e\u003c/script\u003e\n```\n\nThe browser script exposes a variable `CRC32`.\n\nThe script will manipulate `module.exports` if available .  This is not always\ndesirable.  To prevent the behavior, define `DO_NOT_EXPORT_CRC`.\n\n### CRC32C (Castagnoli)\n\nThe module and CDNs also include a parallel script for CRC32C calculations.\n\nUsing NodeJS or a bundler:\n\n```js\nvar CRC32C = require(\"crc-32/crc32c\");\n```\n\nUsing NodeJS or a bundler with `import`:\n\n```js\nimport { bstr, buf, str } from \"crc-32/crc32c\";\n```\n\nIn the browser, the `crc32c.js` script can be loaded directly:\n\n```html\n\u003cscript src=\"crc32c.js\"\u003e\u003c/script\u003e\n```\n\nThe browser exposes a variable `CRC32C`.\n\nThe script will manipulate `module.exports` if available .  This is not always\ndesirable.  To prevent the behavior, define `DO_NOT_EXPORT_CRC`.\n\n## Usage\n\nIn all cases, the relevant function takes an argument representing data and an\noptional second argument representing the starting \"seed\" (for rolling CRC).\n\n**The return value is a signed 32-bit integer!**\n\n- `CRC32.buf(byte array or buffer[, seed])` assumes the argument is a sequence\n  of 8-bit unsigned integers (nodejs `Buffer`, `Uint8Array` or array of bytes).\n\n- `CRC32.bstr(binary string[, seed])` assumes the argument is a binary string\n  where byte `i` is the low byte of the UCS-2 char: `str.charCodeAt(i) \u0026 0xFF`\n\n- `CRC32.str(string[, seed])` assumes the argument is a standard JS string and\n  calculates the hash of the UTF-8 encoding.\n\nFor example:\n\n```js\n// var CRC32 = require('crc-32');               // uncomment this line if in node\nCRC32.str(\"SheetJS\")                            // -1647298270\nCRC32.bstr(\"SheetJS\")                           // -1647298270\nCRC32.buf([ 83, 104, 101, 101, 116, 74, 83 ])   // -1647298270\n\ncrc32 = CRC32.buf([83, 104])                    // -1826163454  \"Sh\"\ncrc32 = CRC32.str(\"eet\", crc32)                 //  1191034598  \"Sheet\"\nCRC32.bstr(\"JS\", crc32)                         // -1647298270  \"SheetJS\"\n\n[CRC32.str(\"\\u2603\"),  CRC32.str(\"\\u0003\")]     // [ -1743909036,  1259060791 ]\n[CRC32.bstr(\"\\u2603\"), CRC32.bstr(\"\\u0003\")]    // [  1259060791,  1259060791 ]\n[CRC32.buf([0x2603]),  CRC32.buf([0x0003])]     // [  1259060791,  1259060791 ]\n\n// var CRC32C = require('crc-32/crc32c');       // uncomment this line if in node\nCRC32C.str(\"SheetJS\")                           // -284764294\nCRC32C.bstr(\"SheetJS\")                          // -284764294\nCRC32C.buf([ 83, 104, 101, 101, 116, 74, 83 ])  // -284764294\n\ncrc32c = CRC32C.buf([83, 104])                  // -297065629   \"Sh\"\ncrc32c = CRC32C.str(\"eet\", crc32c)              //  1241364256  \"Sheet\"\nCRC32C.bstr(\"JS\", crc32c)                       // -284764294   \"SheetJS\"\n\n[CRC32C.str(\"\\u2603\"),  CRC32C.str(\"\\u0003\")]   // [  1253703093,  1093509285 ]\n[CRC32C.bstr(\"\\u2603\"), CRC32C.bstr(\"\\u0003\")]  // [  1093509285,  1093509285 ]\n[CRC32C.buf([0x2603]),  CRC32C.buf([0x0003])]   // [  1093509285,  1093509285 ]\n```\n\n### Best Practices\n\nEven though the initial seed is optional, for performance reasons it is highly\nrecommended to explicitly pass the default seed 0.\n\nIn NodeJS with the native Buffer implementation, it is oftentimes faster to\nconvert binary strings with `Buffer.from(bstr, \"binary\")` first:\n\n```js\n/* Frequently slower in NodeJS */\ncrc32 = CRC32.bstr(bstr, 0);\n/* Frequently faster in NodeJS */\ncrc32 = CRC32.buf(Buffer.from(bstr, \"binary\"), 0);\n```\n\nThis does not apply to browser `Buffer` shims, and thus is not implemented in\nthe library directly.\n\n### Signed Integers\n\nUnconventional for a CRC32 checksum, this library uses signed 32-bit integers.\nThis is for performance reasons.  Standard JS operators can convert between\nsigned and unsigned 32-bit integers:\n\n```js\nCRC32.str(\"SheetJS\")                            // -1647298270 (signed)\nCRC32.str(\"SheetJS\") \u003e\u003e\u003e 0                      //  2647669026 (unsigned)\n(CRC32.str(\"SheetJS\")\u003e\u003e\u003e0).toString(16)         //  \"9dd03922\" (hex)\n\n(2647669026 | 0)                                // -1647298270\n```\n\n- `x \u003e\u003e\u003e 0` converts a number value to unsigned 32-bit integer.\n\n- `x | 0` converts a number value to signed 32-bit integer.\n\n\n## Testing\n\n`make test` will run the nodejs-based test.\n\nTo run the in-browser tests, run a local server and go to the `ctest` directory.\n`make ctestserv` will start a python `SimpleHTTPServer` server on port 8000.\n\nTo update the browser artifacts, run `make ctest`.\n\nTo generate the bits file, use the `crc32` function from python `zlib`:\n\n```python\n\u003e\u003e\u003e from zlib import crc32\n\u003e\u003e\u003e x=\"foo bar baz٪☃🍣\"\n\u003e\u003e\u003e crc32(x)\n1531648243\n\u003e\u003e\u003e crc32(x+x)\n-218791105\n\u003e\u003e\u003e crc32(x+x+x)\n1834240887\n```\n\nThe included `crc32.njs` script can process files or standard input:\n\n```bash\n$ echo \"this is a test\" \u003e t.txt\n$ bin/crc32.njs t.txt\n1912935186\n```\n\nFor comparison, the included `crc32.py` script uses python `zlib`:\n\n```bash\n$ bin/crc32.py t.txt\n1912935186\n```\n\nOn OSX the command `cksum` generates unsigned CRC-32 with Algorithm 3:\n\n```bash\n$ cksum -o 3 \u003c IE8.Win7.For.Windows.VMware.zip\n1891069052 4161613172\n$ crc32 --unsigned ~/Downloads/IE8.Win7.For.Windows.VMware.zip\n1891069052\n```\n\n## Performance\n\n`make perf` will run algorithmic performance tests (which should justify certain\ndecisions in the code).\n\nThe [`adler-32` project](https://github.com/SheetJS/js-adler32) has more performance notes\n\n## License\n\nPlease consult the attached LICENSE file for details.  All rights not explicitly\ngranted by the Apache 2.0 license are reserved by the Original Author.\n\n## Badges\n\n[![Sauce Test Status](https://saucelabs.com/browser-matrix/crc32.svg)](https://saucelabs.com/u/crc32)\n\n[![Build Status](https://travis-ci.org/SheetJS/js-crc32.svg?branch=master)](https://travis-ci.org/SheetJS/js-crc32)\n[![Coverage Status](http://img.shields.io/coveralls/SheetJS/js-crc32/master.svg)](https://coveralls.io/r/SheetJS/js-crc32?branch=master)\n[![Dependencies Status](https://david-dm.org/sheetjs/js-crc32/status.svg)](https://david-dm.org/sheetjs/js-crc32)\n[![NPM Downloads](https://img.shields.io/npm/dt/crc-32.svg)](https://npmjs.org/package/crc-32)\n[![ghit.me](https://ghit.me/badge.svg?repo=sheetjs/js-xlsx)](https://ghit.me/repo/sheetjs/js-xlsx)\n[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-crc32?pixel)](https://github.com/SheetJS/js-crc32)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":["Data"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSheetJS%2Fjs-crc32","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSheetJS%2Fjs-crc32","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSheetJS%2Fjs-crc32/lists"}