Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(796)

Side by Side Diff: common/dirwalk/tests/tools/walkdir/walkers_size.go

Issue 2054763004: luci-go/common/dirwalk: Code for walking a directory tree efficiently Base URL: https://github.com/luci/luci-go@master
Patch Set: Fixes. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698