From 61c0908b1355e39d5c9570ba18116ea1a06d155e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 18 Apr 2021 03:33:01 +0900 Subject: [PATCH] internal/glfw: Refactoring --- internal/glfw/gen.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/glfw/gen.go b/internal/glfw/gen.go index 42323a0e3..4f1eedb91 100644 --- a/internal/glfw/gen.go +++ b/internal/glfw/gen.go @@ -17,11 +17,10 @@ package main import ( - "bytes" "crypto/sha256" "encoding/hex" "fmt" - "io/ioutil" + "io" "os" "os/exec" "path/filepath" @@ -111,10 +110,14 @@ func run() error { return err } - in, err := ioutil.ReadFile(dll) + dllf, err := os.Open(dll) if err != nil { return err } + defer dllf.Close() + + hash := sha256.New() + in := io.TeeReader(dllf, hash) out, err := os.Create(fmt.Sprintf("glfwdll_windows_%s.go", arch)) if err != nil { @@ -123,7 +126,7 @@ func run() error { defer out.Close() // As the file name already specified the build environment, buildtags are not requried. - if err := file2byteslice.Write(out, bytes.NewReader(in), true, "", "glfw", "glfwDLLCompressed"); err != nil { + if err := file2byteslice.Write(out, in, true, "", "glfw", "glfwDLLCompressed"); err != nil { return err } @@ -133,13 +136,14 @@ func run() error { return err } defer hashout.Close() - hash := sha256.Sum256(in) + + hashsum := hash.Sum(nil) if _, err := fmt.Fprintf(hashout, `// Code generated by gen.go. DO NOT EDIT. package glfw const glfwDLLHash = "%s" -`, hex.EncodeToString(hash[:])); err != nil { +`, hex.EncodeToString(hashsum[:])); err != nil { return err }