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 "os" |
| 11 ) |
| 12 |
| 13 // SizeWalker implements Walker. It prints the size of every file. |
| 14 type SizeWalker struct { |
| 15 BaseWalker |
| 16 obuf io.Writer |
| 17 } |
| 18 |
| 19 func (s *SizeWalker) SizeFile(filename string, size int64) { |
| 20 fmt.Fprintf(s.obuf, "%s: %d\n", filename, size) |
| 21 } |
| 22 |
| 23 func (s *SizeWalker) SmallFile(filename string, alldata []byte) { |
| 24 s.BaseWalker.SmallFile(filename, alldata) |
| 25 s.SizeFile(filename, int64(len(alldata))) |
| 26 } |
| 27 |
| 28 func (s *SizeWalker) LargeFile(filename string) { |
| 29 s.BaseWalker.LargeFile(filename) |
| 30 stat, err := os.Stat(filename) |
| 31 if err != nil { |
| 32 s.Error(filename, err) |
| 33 } else { |
| 34 s.SizeFile(filename, stat.Size()) |
| 35 } |
| 36 } |
OLD | NEW |