Index: common/dirwalk/tests/tools/walkdir/walkers_hash.go |
diff --git a/common/dirwalk/tests/tools/walkdir/walkers_hash.go b/common/dirwalk/tests/tools/walkdir/walkers_hash.go |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f88ebb09b6f98a4579931e8242a590f1bcd79d0b |
--- /dev/null |
+++ b/common/dirwalk/tests/tools/walkdir/walkers_hash.go |
@@ -0,0 +1,34 @@ |
+// Copyright 2016 The LUCI Authors. All rights reserved. |
+// Use of this source code is governed under the Apache License, Version 2.0 |
+// that can be found in the LICENSE file. |
+ |
+package main |
+ |
+import ( |
+ "fmt" |
+ "io" |
+ |
+ "github.com/luci/luci-go/common/isolated" |
+) |
+ |
+// HashWalker implements Walker. It generates a hash for the contents of each |
+// found file. |
+type HashWalker struct { |
+ BaseWalker |
+ obuf io.Writer |
+} |
+ |
+func (h *HashWalker) HashedFile(filename string, digest isolated.HexDigest) { |
+ fmt.Fprintf(h.obuf, "%s: %v\n", filename, digest) |
+} |
+ |
+func (h *HashWalker) SmallFile(filename string, alldata []byte) { |
+ h.BaseWalker.SmallFile(filename, alldata) |
+ h.HashedFile(filename, isolated.HashBytes(alldata)) |
+} |
+ |
+func (h *HashWalker) LargeFile(filename string) { |
+ h.BaseWalker.LargeFile(filename) |
+ d, _ := isolated.HashFile(filename) |
+ h.HashedFile(filename, isolated.HexDigest(d.Digest)) |
+} |