(filePath: string)
| 2 | import fs from 'node:fs' |
| 3 | |
| 4 | export function getHash(filePath: string): Promise<string> { |
| 5 | const hash = crypto.createHash('sha256') |
| 6 | const input = fs.createReadStream(filePath) |
| 7 | return new Promise((resolve) => { |
| 8 | input.on('readable', () => { |
| 9 | const data = input.read() |
| 10 | if (data) { |
| 11 | hash.update(data) |
| 12 | } else { |
| 13 | resolve(hash.digest('hex')) |
| 14 | } |
| 15 | }) |
| 16 | }) |
| 17 | } |