OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package main |
| 6 |
| 7 import ( |
| 8 "fmt" |
| 9 "io" |
| 10 |
| 11 "github.com/luci/luci-go/common/isolated" |
| 12 ) |
| 13 |
| 14 // HashWalker implements Walker. It generates a hash for the contents of each |
| 15 // found file. |
| 16 type HashWalker struct { |
| 17 BaseWalker |
| 18 obuf io.Writer |
| 19 } |
| 20 |
| 21 func (h *HashWalker) HashedFile(filename string, digest isolated.HexDigest) { |
| 22 fmt.Fprintf(h.obuf, "%s: %v\n", filename, digest) |
| 23 } |
| 24 |
| 25 func (h *HashWalker) SmallFile(filename string, alldata []byte) { |
| 26 h.BaseWalker.SmallFile(filename, alldata) |
| 27 h.HashedFile(filename, isolated.HashBytes(alldata)) |
| 28 } |
| 29 |
| 30 func (h *HashWalker) LargeFile(filename string) { |
| 31 h.BaseWalker.LargeFile(filename) |
| 32 d, _ := isolated.HashFile(filename) |
| 33 h.HashedFile(filename, isolated.HexDigest(d.Digest)) |
| 34 } |
OLD | NEW |