const path = require('path');
|
const fs = require('fs');
|
const crypto = require('crypto');
|
|
// const YOUR_FILE_PATH = 'resXmlParser-1.2.2-update.exe'; // POPULATE THIS
|
const YOUR_FILE_PATH = 'resXmlParser-1.2.2-standard-update.exe'; // POPULATE THIS
|
|
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,
|
}
|
);
|
});
|
}
|
|
function getSize(filePath) {
|
|
fs.stat(filePath, (err, stats) => {
|
if (err) {
|
console.error(err);
|
return;
|
}
|
|
const fileSizeInBytes = stats.size;
|
// const fileSizeInMB = fileSizeInBytes / (1024 * 1024); // 转换为MB
|
|
// console.log(`文件大小: ${fileSizeInMB} MB`);
|
console.log(`文件名称: ${YOUR_FILE_PATH}`);
|
console.log(`文件大小: ${fileSizeInBytes}`);
|
});
|
}
|
|
const installerPath = path.resolve(
|
__dirname,
|
YOUR_FILE_PATH
|
);
|
|
hashFile(installerPath);
|
getSize(installerPath);
|