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)
| 663 | // pipe based on the provided hasher, or an error. |
| 664 | // To perform hashing on files, see [Pipe.HashSums]. |
| 665 | func (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, |