gui/.github/get-shasum-file.js
Neil a1be911397
#209 implement electron-updater (#210)
* #209 implement electron-updater: enable gui to auto update if there are new builds in s3
---------

Co-authored-by: neil <neil@neils-MacBook-Pro.local>
2023-02-21 21:03:24 +08:00

32 lines
No EOL
797 B
JavaScript
Executable file

const { createHash } = require("crypto");
const { createReadStream } = require("fs");
const file = "tea-0.0.2-arm64.dmg";
function hashFile(file, encoding = "base64") {
return new Promise((resolve, reject) => {
const hash = createHash("sha512")
hash.on("error", reject).setEncoding(encoding)
createReadStream(file, { highWaterMark: 1024 * 1024 /* better to use more memory but hash faster */ })
.on("error", reject)
.on("end", () => {
hash.end()
resolve(hash.read())
})
.pipe(hash, { end: false })
})
}
// hashFile(file)
// .then((res) => {
// console.log("res",res)
// })
async function main() {
const args = process.argv;
const filePath = args.pop();
const hash = await hashFile(filePath);
console.log(hash);
}
main();