Support Castagnoli CRC32 #16

Closed
opened 2020-08-25 04:04:50 +00:00 by junderw · 4 comments
junderw commented 2020-08-25 04:04:50 +00:00 (Migrated from github.com)

https://stackoverflow.com/questions/26429360/crc32-vs-crc32c

We would need to replace each instance of -306674912 in the signed_crc_table function. Which means we would need to decide on a way to switch between the two constants. (Default would be -306674912 so it won't be a breaking change)

The new constant for Castagnoli is -2097792136

> 0x82F63B78 << 0
-2097792136

Please let me know:

  1. If you would be interested in adding this?
  2. Would you be comfortable with me creating a pull request for this?

If yes for both, I'll go ahead and make a proposal/PR. Thanks.

https://stackoverflow.com/questions/26429360/crc32-vs-crc32c We would need to replace each instance of `-306674912` in the `signed_crc_table` function. Which means we would need to decide on a way to switch between the two constants. (Default would be `-306674912` so it won't be a breaking change) The new constant for Castagnoli is `-2097792136` ``` > 0x82F63B78 << 0 -2097792136 ``` Please let me know: 1. If you would be interested in adding this? 2. Would you be comfortable with me creating a pull request for this? If yes for both, I'll go ahead and make a proposal/PR. Thanks.
trivikr commented 2021-04-27 15:28:33 +00:00 (Migrated from github.com)

I ended up on this request while searching for pure JS CRC32C implementations, after benchmarking crc32 implementations in https://github.com/trivikr/benchmark-crc32

I noticed that original author @junderw forked this repo at https://github.com/junderw/js-crc32, and published the fork with crc32c implementation at junderw-crc32c.

The commit which introduced CRC32c implementation: b06adcad53

I ended up on this request while searching for pure JS CRC32C implementations, after benchmarking crc32 implementations in https://github.com/trivikr/benchmark-crc32 I noticed that original author @junderw forked this repo at https://github.com/junderw/js-crc32, and published the fork with crc32c implementation at [junderw-crc32c](https://www.npmjs.com/package/junderw-crc32c). The commit which introduced CRC32c implementation: https://github.com/junderw/js-crc32/commit/b06adcad53c4aa05693d2ad3bcf65997975896bd
trivikr commented 2021-04-27 16:38:05 +00:00 (Migrated from github.com)

cc maintainer @SheetJSDev to check if CRC32c implementation can be added in crc-32 package.

cc maintainer @SheetJSDev to check if CRC32c implementation can be added in `crc-32` package.
SheetJSDev commented 2022-01-24 08:31:27 +00:00 (Migrated from github.com)

Instead of disrupting the original interface, a parallel script using the CRC32C constant has been added to the source tree and will be rolled out in the next npm publish. It is implemented in the obvious way (string replace of the number).

It is accessible at crc-32/crc32c and has the same type signature as the base library. For example, normal CJS code will use:

var CRC32C = require("crc-32/crc32c");
console.log((CRC32C.bstr("SheetJS")>>>0).toString(16));

TS code can use named imports:

import { bstr } from "crc-32/crc32c";
console.log((bstr("SheetJS")>>>0).toString(16));

Bundlers will only pull in the imported scripts, so importing the crc-32/crc32c submodule will not pull in the main crc-32 module code and vice versa.

The command-line script has been updated with a new option:

    -c, --crc32c         use CRC32C (Castagnoli)

Example:

$ echo -n SheetJS | node_modules/.bin/crc32 -x    # standard CRC32
9dd03922
$ echo -n SheetJS | node_modules/.bin/crc32 -x -c # CRC32C
ef06d77a
Instead of disrupting the original interface, a [parallel script using the CRC32C constant](https://github.com/SheetJS/js-crc32/blob/master/crc32c.js) has been added to the source tree and will be rolled out in the next npm publish. It is implemented in the obvious way (string replace of the number). It is accessible at `crc-32/crc32c` and has the same type signature as the base library. For example, normal CJS code will use: ```js var CRC32C = require("crc-32/crc32c"); console.log((CRC32C.bstr("SheetJS")>>>0).toString(16)); ``` TS code can use named imports: ```typescript import { bstr } from "crc-32/crc32c"; console.log((bstr("SheetJS")>>>0).toString(16)); ``` Bundlers will only pull in the imported scripts, so importing the `crc-32/crc32c` submodule will not pull in the main `crc-32` module code and vice versa. The command-line script has been updated with a new option: ``` -c, --crc32c use CRC32C (Castagnoli) ``` Example: ``` $ echo -n SheetJS | node_modules/.bin/crc32 -x # standard CRC32 9dd03922 $ echo -n SheetJS | node_modules/.bin/crc32 -x -c # CRC32C ef06d77a ```
SheetJSDev commented 2022-01-25 06:04:02 +00:00 (Migrated from github.com)

version 1.2.1 is now published on npm. CDN script https://unpkg.com/crc-32/crc32c.js

Types appear to work for both the main module and submodule, as verified in a new Vanilla Typescript CodeSandbox (add the crc-32 dependency and it will detect the import types for "crc-32" and for "crc-32/crc32c"

The bin script has been updated as well

$ echo -n SheetJS | npx crc-32 -c -x
ef06d77a

@trivikr FYI the new buf implementation using slice-by-16 (thanks @101arrowz !) is noticeably faster both in browser and in nodejs. We'll try to send a PR to the benchmark repo

version 1.2.1 is now published on npm. CDN script https://unpkg.com/crc-32/crc32c.js Types appear to work for both the main module and submodule, as verified in a new Vanilla Typescript CodeSandbox (add the `crc-32` dependency and it will detect the import types for "crc-32" and for "crc-32/crc32c" The bin script has been updated as well ``` $ echo -n SheetJS | npx crc-32 -c -x ef06d77a ``` @trivikr FYI the new `buf` implementation using slice-by-16 (thanks @101arrowz !) is noticeably faster both in browser and in nodejs. We'll try to send a PR to the benchmark repo
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/js-crc32#16
No description provided.