MCPcopy Index your code
hub / github.com/WendellCraft/ModpackDebuggerKit / getSHA1Hash

Function getSHA1Hash

modrinth.go:14–26  ·  view source on GitHub ↗
(filePath string)

Source from the content-addressed store, hash-verified

12const modrinthAPIBase = "https://api.modrinth.com/v2"
13
14func getSHA1Hash(filePath string) (string, error) {
15 f, err := os.Open(filePath)
16 if err != nil {
17 return "", fmt.Errorf("error opening file %s: %w", filePath, err)
18 }
19 defer f.Close()
20
21 h := sha1.New()
22 if _, err := io.CopyBuffer(h, f, make([]byte, 65536)); err != nil {
23 return "", fmt.Errorf("error reading file %s: %w", filePath, err)
24 }
25 return fmt.Sprintf("%x", h.Sum(nil)), nil
26}
27
28func getModInfo(sha1Hash string) (*ModrinthVersion, error) {
29 url := fmt.Sprintf("%s/version_file/%s", modrinthAPIBase, sha1Hash)

Callers 1

modrinthSyncMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected