MCPcopy
hub / github.com/bitfield/script / Hash

Method Hash

script.go:665–675  ·  view source on GitHub ↗

Hash returns the hex-encoded hash of the entire contents of the pipe based on the provided hasher, or an error. To perform hashing on files, see [Pipe.HashSums].

(hasher hash.Hash)

Source from the content-addressed store, hash-verified

663// pipe based on the provided hasher, or an error.
664// To perform hashing on files, see [Pipe.HashSums].
665func (p *Pipe) Hash(hasher hash.Hash) (string, error) {
666 if p.Error() != nil {
667 return "", p.Error()
668 }
669 _, err := io.Copy(hasher, p)
670 if err != nil {
671 p.SetError(err)
672 return "", err
673 }
674 return hex.EncodeToString(hasher.Sum(nil)), nil
675}
676
677// HashSums reads paths from the pipe, one per line, and produces the
678// hex-encoded hash of each corresponding file based on the provided hasher,

Callers 4

SHA256SumMethod · 0.95
ExamplePipe_HashFunction · 0.80

Calls 2

ErrorMethod · 0.95
SetErrorMethod · 0.95

Tested by 3

ExamplePipe_HashFunction · 0.64