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 "io/ioutil" |
| 11 "os" |
| 12 ) |
| 13 |
| 14 // SizeFileProcessor implements FileProcessor. It prints the size of every file. |
| 15 type SizeFileProcessor struct { |
| 16 BaseFileProcessor |
| 17 obuf io.Writer |
| 18 } |
| 19 |
| 20 func (p *SizeFileProcessor) SizeFile(path string, size int64) { |
| 21 fmt.Fprintf(p.obuf, "%s: %d\n", path, size) |
| 22 } |
| 23 |
| 24 func (p *SizeFileProcessor) SmallFile(path string, r io.ReadCloser) { |
| 25 bytes, err := io.Copy(ioutil.Discard, r) |
| 26 if err != nil { |
| 27 p.Error(path, err) |
| 28 } |
| 29 p.SizeFile(path, int64(bytes)) |
| 30 |
| 31 p.BaseFileProcessor.SmallFile(path, r) |
| 32 } |
| 33 |
| 34 func (p *SizeFileProcessor) LargeFile(path string, r io.ReadCloser) { |
| 35 fi, err := os.Stat(path) |
| 36 if err != nil { |
| 37 p.Error(path, err) |
| 38 } else { |
| 39 p.SizeFile(path, fi.Size()) |
| 40 } |
| 41 p.BaseFileProcessor.LargeFile(path, r) |
| 42 } |
OLD | NEW |