HashSums reads paths from the pipe, one per line, and produces the hex-encoded hash of each corresponding file based on the provided hasher, one per line. Any files that cannot be opened or read will be ignored. To perform hashing on the contents of the pipe, see [Pipe.Hash].
(hasher hash.Hash)
| 679 | // one per line. Any files that cannot be opened or read will be ignored. |
| 680 | // To perform hashing on the contents of the pipe, see [Pipe.Hash]. |
| 681 | func (p *Pipe) HashSums(hasher hash.Hash) *Pipe { |
| 682 | return p.FilterScan(func(line string, w io.Writer) { |
| 683 | f, err := os.Open(line) |
| 684 | if err != nil { |
| 685 | return // skip unopenable files |
| 686 | } |
| 687 | defer f.Close() |
| 688 | _, err = io.Copy(hasher, f) |
| 689 | if err != nil { |
| 690 | return // skip unreadable files |
| 691 | } |
| 692 | fmt.Fprintln(w, hex.EncodeToString(hasher.Sum(nil))) |
| 693 | }) |
| 694 | } |
| 695 | |
| 696 | // Join joins all the lines in the pipe's contents into a single |
| 697 | // space-separated string, which will always end with a newline. |