From 715e9439a1fcd0edf33dc1bda125c0c386c8443b Mon Sep 17 00:00:00 2001 From: Tricked <72335827+SkyBlockDev@users.noreply.github.com> Date: Wed, 15 Jun 2022 15:26:32 +0200 Subject: [PATCH] fix: file hashing --- github/install.go | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/github/install.go b/github/install.go index a39941c..034ed81 100644 --- a/github/install.go +++ b/github/install.go @@ -1,13 +1,10 @@ package github import ( - "crypto/sha256" "encoding/json" "errors" "fmt" - "io" "io/ioutil" - "log" "net/http" "os" "path/filepath" @@ -339,12 +336,6 @@ type Asset struct { func (u Asset) getSha256() (string, error) { // TODO potentionally cache downloads to speed things up and avoid getting ratelimited by github! - file, err := os.CreateTemp("", "download") - - if err != nil { - fmt.Println(err) - os.Exit(1) - } mainHasher, err := core.GetHashImpl("sha256") resp, err := http.Get(u.BrowserDownloadURL) if err != nil { @@ -360,17 +351,9 @@ func (u Asset) getSha256() (string, error) { defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) + mainHasher.Write(body) - file.Write(body) - - h := sha256.New() - if _, err := io.Copy(h, file); err != nil { - log.Fatal(err) - } - - hash := h.Sum(nil) - - defer os.Remove(file.Name()) + hash := mainHasher.Sum(nil) return mainHasher.HashToString(hash), nil }