-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] app.asar 파일의 체크섬을 추출하는 함수 따로 스크립트로 추출
- 인자는 app.asar 가 존재하는 디렉토리경로
- Loading branch information
1 parent
71da415
commit 1aec48b
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |