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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
Index: common/dirwalk/tests/tools/walkdir/walkers_size.go
diff --git a/common/dirwalk/tests/tools/walkdir/walkers_size.go b/common/dirwalk/tests/tools/walkdir/walkers_size.go
new file mode 100644
index 0000000000000000000000000000000000000000..5f1973ca80d4e35343e96a13f558a9b6fe5184bd
--- /dev/null
+++ b/common/dirwalk/tests/tools/walkdir/walkers_size.go
@@ -0,0 +1,36 @@
+// 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"
+ "os"
+)
+
+// SizeWalker implements Walker. It prints the size of every file.
+type SizeWalker struct {
+ BaseWalker
+ obuf io.Writer
+}
+
+func (s *SizeWalker) SizeFile(filename string, size int64) {
+ fmt.Fprintf(s.obuf, "%s: %d\n", filename, size)
+}
+
+func (s *SizeWalker) SmallFile(filename string, alldata []byte) {
+ s.BaseWalker.SmallFile(filename, alldata)
+ s.SizeFile(filename, int64(len(alldata)))
+}
+
+func (s *SizeWalker) LargeFile(filename string) {
+ s.BaseWalker.LargeFile(filename)
+ stat, err := os.Stat(filename)
+ if err != nil {
+ s.Error(filename, err)
+ } else {
+ s.SizeFile(filename, stat.Size())
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698