(filePaths: string[])
| 7 | * @returns Combined SHA256 hash of all files, or empty string if no files exist |
| 8 | */ |
| 9 | export function hashFiles(filePaths: string[]): string { |
| 10 | const combinedHash = createHash('sha256'); |
| 11 | let hasFound = false; |
| 12 | |
| 13 | for (const filePath of filePaths) { |
| 14 | try { |
| 15 | if (fs.pathExistsSync(filePath)) { |
| 16 | const fileContent = fs.readFileSync(filePath); |
| 17 | const fileHash = createHash('sha256').update(new Uint8Array(fileContent)).digest(); |
| 18 | combinedHash.write(fileHash); |
| 19 | hasFound = true; |
| 20 | } |
| 21 | } catch (err: any) { |
| 22 | throw new Error(`Failed to hash file ${filePath}: ${err.message}`); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | combinedHash.end(); |
| 27 | const result = combinedHash.digest('hex'); |
| 28 | |
| 29 | if (!hasFound) { |
| 30 | return ''; |
| 31 | } |
| 32 | |
| 33 | return result; |
| 34 | } |
no test coverage detected
searching dependent graphs…