| Index: common/dirwalk/tests/tools/walkdir/fileprocessor_size.go
|
| diff --git a/common/dirwalk/tests/tools/walkdir/fileprocessor_size.go b/common/dirwalk/tests/tools/walkdir/fileprocessor_size.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bcb1fd6aaa1b365fadf1f06f05fa59603003230d
|
| --- /dev/null
|
| +++ b/common/dirwalk/tests/tools/walkdir/fileprocessor_size.go
|
| @@ -0,0 +1,42 @@
|
| +// 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"
|
| + "io/ioutil"
|
| + "os"
|
| +)
|
| +
|
| +// SizeFileProcessor implements FileProcessor. It prints the size of every file.
|
| +type SizeFileProcessor struct {
|
| + BaseFileProcessor
|
| + obuf io.Writer
|
| +}
|
| +
|
| +func (p *SizeFileProcessor) SizeFile(path string, size int64) {
|
| + fmt.Fprintf(p.obuf, "%s: %d\n", path, size)
|
| +}
|
| +
|
| +func (p *SizeFileProcessor) SmallFile(path string, r io.ReadCloser) {
|
| + bytes, err := io.Copy(ioutil.Discard, r)
|
| + if err != nil {
|
| + p.Error(path, err)
|
| + }
|
| + p.SizeFile(path, int64(bytes))
|
| +
|
| + p.BaseFileProcessor.SmallFile(path, r)
|
| +}
|
| +
|
| +func (p *SizeFileProcessor) LargeFile(path string, r io.ReadCloser) {
|
| + fi, err := os.Stat(path)
|
| + if err != nil {
|
| + p.Error(path, err)
|
| + } else {
|
| + p.SizeFile(path, fi.Size())
|
| + }
|
| + p.BaseFileProcessor.LargeFile(path, r)
|
| +}
|
|
|