Open KodeurKubik opened 9 months ago
1.0.18+36c316a24
Darwin 23.1.0 arm64 arm
Getting the sha256 of a file with crypto and stream throws an error. Use this code:
const { randomBytes, createHash } = require("node:crypto"); const { createReadStream } = require('fs'); const stream = require('stream/promises'); async computeHash(filepath, hashing = 'sha256') { const input = createReadStream(filepath); const hash = createHash(hashing); await stream.pipeline(input, hash); return hash.digest('hex'); }
And use the function computeHash on any file, bun will throw the following error:
computeHash
10 | const input = createReadStream(filepath); 11 | const hash = createHash(hashing); 12 | 13 | await stream.pipeline(input, hash); 14 | 15 | return hash.digest('hex'); ^ error: Digest already called code: "ERR_CRYPTO_HASH_FINALIZED" at _checkFinalized (node:crypto:1175:137) at update (node:crypto:1173:101) at /path/to/file/index.js:15:16 at processTicksAndRejections (:61:77)
Expected behavior is like using node, the function should return an hexadecimal sha256 string.
Well, the error like written in "What steps can reproduce the bug"
No response
+1
What version of Bun is running?
1.0.18+36c316a24
What platform is your computer?
Darwin 23.1.0 arm64 arm
What steps can reproduce the bug?
Getting the sha256 of a file with crypto and stream throws an error. Use this code:
And use the function
computeHash
on any file, bun will throw the following error:What is the expected behavior?
Expected behavior is like using node, the function should return an hexadecimal sha256 string.
What do you see instead?
Well, the error like written in "What steps can reproduce the bug"
Additional information
No response