(filePath: string)
| 6 | * @returns A promise that resolves to the hash string of the file. |
| 7 | */ |
| 8 | export async function calculateFileHash(filePath: string): Promise<string> { |
| 9 | return new Promise((resolve, reject) => { |
| 10 | const hash = createHash('sha256'); // or 'md5', 'sha1', etc. |
| 11 | const stream = createReadStream(filePath); |
| 12 | |
| 13 | stream.on('error', err => reject(err)); |
| 14 | stream.on('data', chunk => hash.update(chunk)); |
| 15 | stream.on('end', () => resolve(hash.digest('hex'))); |
| 16 | }); |
| 17 | } |