From: Tamir Duberstein Date: Tue, 12 Oct 2021 20:00:23 +0000 (-0400) Subject: os: Simplify size using io.Discard. X-Git-Tag: go1.18beta1~928 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3283d1a2f29496d882b6edc57543446967dc8233;p=gostls13.git os: Simplify size using io.Discard. Change-Id: Ib7cc86643a3dcae788a94472e54de171e0d655fc Reviewed-on: https://go-review.googlesource.com/c/go/+/355449 Trust: Michael Pratt Trust: Keith Randall Run-TryBot: Michael Pratt TryBot-Result: Go Bot Reviewed-by: Michael Pratt --- diff --git a/src/os/os_test.go b/src/os/os_test.go index 62173d9bf4..717330e86a 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -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) {