Last active
October 13, 2023 20:13
-
-
Save ValentaTomas/56aa5fd6f8c1121a237fdd1968d95bba to your computer and use it in GitHub Desktop.
Hash files
This file contains hidden or 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
import * as crypto from 'crypto' | |
const delimiter = '\0' | |
export function getFilesHash(files: { name: string; content: string }[]) { | |
const shasum = crypto.createHash('sha1') | |
files.forEach(({ name, content }) => { | |
shasum.update(name) | |
// Add delimiter to hash to prevent collisions between files where the join of the name and content is the same | |
shasum.update(delimiter) | |
shasum.update(content) | |
shasum.update(delimiter) | |
}) | |
return shasum.digest('base64') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment