-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use worker thread for piece hashing
- Loading branch information
Alan Shaw
committed
Jun 24, 2024
1 parent
2a60b1b
commit 5ce8608
Showing
3 changed files
with
45 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { parentPort, workerData } from 'node:worker_threads' | ||
import * as PieceHasher from 'fr32-sha2-256-trunc254-padded-binary-tree-multihash' | ||
|
||
const hasher = PieceHasher.create() | ||
hasher.write(workerData) | ||
|
||
const bytes = new Uint8Array(hasher.multihashByteLength()) | ||
hasher.digestInto(bytes, 0, true) | ||
hasher.free() | ||
|
||
parentPort?.postMessage(bytes) |