mirror of https://github.com/golang/go.git
os: Simplify size using io.Discard.
Change-Id: Ib7cc86643a3dcae788a94472e54de171e0d655fc Reviewed-on: https://go-review.googlesource.com/c/go/+/355449 Trust: Michael Pratt <mpratt@google.com> Trust: Keith Randall <khr@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
61890fb123
commit
3283d1a2f2
|
|
@ -115,20 +115,16 @@ func size(name string, t *testing.T) int64 {
|
|||
if err != nil {
|
||||
t.Fatal("open failed:", err)
|
||||
}
|
||||
defer file.Close()
|
||||
var buf [100]byte
|
||||
len := 0
|
||||
for {
|
||||
n, e := file.Read(buf[0:])
|
||||
len += n
|
||||
if e == io.EOF {
|
||||
break
|
||||
}
|
||||
if e != nil {
|
||||
t.Fatal("read failed:", e)
|
||||
defer func() {
|
||||
if err := file.Close(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
n, err := io.Copy(io.Discard, file)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return int64(len)
|
||||
return n
|
||||
}
|
||||
|
||||
func equal(name1, name2 string) (r bool) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue