Last active
November 22, 2023 17:37
-
-
Save nikolayemrikh/c8ee6b0bbeda0a2b65685844d503c6b9 to your computer and use it in GitHub Desktop.
Calculate SHA-1 hash GitHub API v3 way
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
git hash-object ./file | |
# or | |
git hash-object -t blob | |
# or | |
cat ./file | git hash-object --stdin |
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
const crypto = require('crypto'); | |
const getSHA1 = (data) => { | |
return crypto.createHash("sha1").update(data).digest("hex"); | |
}; | |
const getGitHubSHA = (data) => { | |
return getSHA1("blob " + Buffer.byteLength(data) + "\0" + data); | |
}; | |
const str = `some text here`; | |
const sha = getGitHubSHA(str); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment