Skip to content

Commit

Permalink
use hash-wasm to calculate checksum (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
incognitojam authored Feb 19, 2025
1 parent 6e3a276 commit 2c7cfac
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@fontsource-variable/inter": "^5.0.18",
"@fontsource-variable/jetbrains-mono": "^5.0.21",
"comlink": "^4.4.1",
"jssha": "^3.3.1",
"hash-wasm": "^4.12.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"xz-decompress": "^0.2.1"
Expand Down
6 changes: 3 additions & 3 deletions src/workers/image.worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Comlink from 'comlink'

import jsSHA from 'jssha'
import { createSHA256 } from 'hash-wasm'
import { XzReadableStream } from 'xz-decompress'

/**
Expand Down Expand Up @@ -133,7 +133,7 @@ const imageWorker = {
}
}

const shaObj = new jsSHA('SHA-256', 'UINT8ARRAY')
const shaObj = await createSHA256()
let complete
try {
let stream = archiveFile.stream()
Expand Down Expand Up @@ -166,7 +166,7 @@ const imageWorker = {
throw `Error closing file handle: ${e}`
}

const checksum = shaObj.getHash('HEX')
const checksum = shaObj.digest()
if (checksum !== expectedChecksum) {
throw `Checksum mismatch: got ${checksum}, expected ${expectedChecksum}`
}
Expand Down

0 comments on commit 2c7cfac

Please sign in to comment.