-
Notifications
You must be signed in to change notification settings - Fork 790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internalize crc
#3224
Internalize crc
#3224
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
} | ||
|
||
const crc = (current: Uint8Array, previous?: number) => { | ||
let crc = previous === 0 ? 0 : ~~previous! ^ -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one thing I don't get is how this works if previous
is undefined. The original version of this code just asserts it's not undefined but I'm not sure . Will work on some tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~~undefined
evaluates to 0
it seems. (!
is a typescript operator (?))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you link to the original version to see how it was being done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/alexgorbatchev/crc/blob/master/src/calculators/crc32.ts It's this file, I copied basically unmodified other than for adding some type annotations that were missing.
.vscode/settings.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"editor.codeActionsOnSave": { | |||
"source.fixAll.eslint": true | |||
"source.fixAll.eslint": "explicit" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea. It just keeps getting auto updated in my local vscode settings. Lemme remove it. Didn't mean to commit but it just keeps showing up.
} | ||
|
||
const crc = (current: Uint8Array, previous?: number) => { | ||
let crc = previous === 0 ? 0 : ~~previous! ^ -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~~undefined
evaluates to 0
it seems. (!
is a typescript operator (?))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming this file is copied from the original package, I assume a license/source code pointer should be added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, sorry, I had that in here but somehow deleted it. Will re-add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw this got merged wanted to add a super small nit: now the reference points to a GH file, but we should have used a permalink to that file instead (if it moves or changes it will not match what is there in the future))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always nice to drop unnecessary dependencies 🙂. Might be worth checking the results of using a WASM version.
} | ||
|
||
const crc = (current: Uint8Array, previous?: number) => { | ||
let crc = previous === 0 ? 0 : ~~previous! ^ -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you link to the original version to see how it was being done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
This duplicates the
crc32
code from thecrc
dep into an internal utility.