get checksum from file
const crypto = require('crypto');
const fs = require('fs');
function file_to_hash(alogarithm = 'sha1', path, encoding = 'hex') {
return new Promise((resolve, reject) => {
const hash = crypto.createHash(alogarithm);
const rs = fs.createReadStream(path);
rs.on('error', reject);
rs.on('data', (chunk) => hash.update(chunk));
rs.on('end', () => resolve(hash.digest(encoding)));
});
}
Usages
file_to_hash('sha512', 'D:/Repositories/release/file.tgz').then(console.log);

Created at 2022-12-30 07:14:39
Updated at 2023-09-02 21:10:16
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.