Skip to content

Commit

Permalink
[chore] app.asar 파일의 체크섬을 추출하는 함수 따로 스크립트로 추출
Browse files Browse the repository at this point in the history
- 인자는 app.asar 가 존재하는 디렉토리경로
  • Loading branch information
extracold1209 committed Jul 30, 2020
1 parent 71da415 commit 1aec48b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/getChecksumFromAsar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');

module.exports = async(targetDirPath) => {
const asarFilePath = path.resolve(targetDirPath, 'app.asar');
if (!fs.existsSync(asarFilePath)) {
console.warn('target file not found. checked path is ', asarFilePath);
return;
}

try {
const digest = await new Promise((resolve, reject) => {
const checksum = crypto.createHash('sha1');
const readStream = fs.createReadStream(asarFilePath);
readStream.on('data', (data) => {
checksum.update(data);
});
readStream.on('end', () => {
resolve(checksum.digest('hex'));
});
readStream.on('error', (e) => {
reject(e);
});
});

return digest;
} catch (e) {
console.error('error occurred while read stream ', e);
}
};

0 comments on commit 1aec48b

Please sign in to comment.