-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
- Loading branch information
1 parent
5d1dad0
commit 1fbfeef
Showing
8 changed files
with
44 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
import {Buffer} from 'node:buffer'; | ||
import crypto from 'node:crypto'; | ||
import {parentPort} from 'node:worker_threads'; | ||
|
||
parentPort.on('message', message => { | ||
const {algorithm, buffer} = message.value; | ||
parentPort.on('message', ({id, value: {algorithm, buffer}}) => { | ||
const hash = crypto.createHash(algorithm); | ||
hash.update(Buffer.from(buffer)); | ||
const arrayBuffer = hash.digest().buffer; | ||
hash.update(new DataView(buffer)); | ||
const value = hash.digest().buffer; | ||
// Transfering buffer here for consistency, but considering buffer size it might be faster to just leave it for copying, needs perf test | ||
parentPort.postMessage({id: message.id, value: arrayBuffer}, [arrayBuffer]); | ||
parentPort.postMessage({id, value}, [value]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const bufferToHex = buffer => { | ||
const view = new DataView(buffer); | ||
|
||
let hexCodes = ''; | ||
for (let index = 0; index < view.byteLength; index += 4) { | ||
hexCodes += view.getUint32(index).toString(16).padStart(8, '0'); | ||
} | ||
|
||
return hexCodes; | ||
}; |