diff --git a/dockertar-sha256-helper.go b/dockertar-sha256-helper.go index 4a4498ff..ac020af1 100644 --- a/dockertar-sha256-helper.go +++ b/dockertar-sha256-helper.go @@ -1,15 +1,21 @@ package main import ( - "fmt" "compress/gzip" - "os" - "io" "crypto/sha256" + "fmt" + "io" + "os" ) func main() { + // Require one positional argument + if len(os.Args) != 2 { + panic("One positional argument is required") + } reader, err := os.Open(os.Args[1]) + // Close the input file at the end of the function + defer reader.Close() if err != nil { os.Exit(1) } @@ -29,7 +35,8 @@ func main() { panic(err) } } + // We must explicitly close before executing the sum + // as defer will cause an incorrect result w.Close() - fmt.Printf("%x\n", sha_256.Sum(nil)) }