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 |
| 12 // HashFileProcessor implements FileProcessor. It generates a hash for the conte
nts of each |
| 13 // found file. |
| 14 type HashFileProcessor struct { |
| 15 BaseFileProcessor |
| 16 obuf io.Writer |
| 17 } |
| 18 |
| 19 func (p *HashFileProcessor) HashedFile(path string, r io.Reader) { |
| 20 digest, _, err := hash(r) |
| 21 if err != nil { |
| 22 p.Error(path, err) |
| 23 return |
| 24 } |
| 25 fmt.Fprintf(p.obuf, "%s: %v\n", path, digest) |
| 26 } |
| 27 |
| 28 func (p *HashFileProcessor) SmallFile(path string, r io.ReadCloser) { |
| 29 p.HashedFile(path, r) |
| 30 p.BaseFileProcessor.SmallFile(path, r) |
| 31 } |
| 32 |
| 33 func (p *HashFileProcessor) LargeFile(path string, r io.ReadCloser) { |
| 34 p.HashedFile(path, r) |
| 35 p.BaseFileProcessor.LargeFile(path, r) |
| 36 } |
OLD | NEW |