-
Notifications
You must be signed in to change notification settings - Fork 45
/
hashExecutable.js
39 lines (35 loc) · 1.04 KB
/
hashExecutable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
const YOUR_FILE_PATH = './output/gSender-1.4.7-x64.exe';
function hashFile(file, algorithm = 'sha512', encoding = 'base64', options) {
return new Promise((resolve, reject) => {
const hash = crypto.createHash(algorithm);
hash.on('error', reject).setEncoding(encoding);
fs.createReadStream(
file,
Object.assign({}, options, {
highWaterMark: 1024 * 1024,
/* better to use more memory but hash faster */
})
)
.on('error', reject)
.on('end', () => {
hash.end();
console.log('hash done');
console.log(hash.read());
resolve(hash.read());
})
.pipe(
hash,
{
end: false,
}
);
});
}
const installerPath = path.resolve(
__dirname,
YOUR_FILE_PATH
);
hashFile(installerPath);