package execenv import ( "crypto/sha256" "encoding/hex" "hash" "io" ) type shaWriter struct{ h hash.Hash } func sha256New() shaWriter { return shaWriter{h: sha256.New()} } func (s shaWriter) Sum() string { return hex.EncodeToString(s.h.Sum(nil)) } // Write 满足 io.Writer,便于 fileSHA256 之外的流式哈希。 func (s shaWriter) Write(p []byte) (int, error) { return s.h.Write(p) } // 确认 shaWriter 可传给 io.Copy。 var _ io.Writer = shaWriter{}