mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-20 21:36:30 +02:00
fix: file hashing
This commit is contained in:
parent
07033023af
commit
715e9439a1
@ -1,13 +1,10 @@
|
|||||||
package github
|
package github
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -339,12 +336,6 @@ type Asset struct {
|
|||||||
|
|
||||||
func (u Asset) getSha256() (string, error) {
|
func (u Asset) getSha256() (string, error) {
|
||||||
// TODO potentionally cache downloads to speed things up and avoid getting ratelimited by github!
|
// 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")
|
mainHasher, err := core.GetHashImpl("sha256")
|
||||||
resp, err := http.Get(u.BrowserDownloadURL)
|
resp, err := http.Get(u.BrowserDownloadURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -360,17 +351,9 @@ func (u Asset) getSha256() (string, error) {
|
|||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
mainHasher.Write(body)
|
||||||
|
|
||||||
file.Write(body)
|
hash := mainHasher.Sum(nil)
|
||||||
|
|
||||||
h := sha256.New()
|
|
||||||
if _, err := io.Copy(h, file); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
hash := h.Sum(nil)
|
|
||||||
|
|
||||||
defer os.Remove(file.Name())
|
|
||||||
|
|
||||||
return mainHasher.HashToString(hash), nil
|
return mainHasher.HashToString(hash), nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user