]> Cypherpunks repositories - gostls13.git/commitdiff
os: Simplify size using io.Discard.
authorTamir Duberstein <tamird@google.com>
Tue, 12 Oct 2021 20:00:23 +0000 (16:00 -0400)
committerMichael Pratt <mpratt@google.com>
Tue, 12 Oct 2021 21:30:45 +0000 (21:30 +0000)
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>
src/os/os_test.go

index 62173d9bf4499ecc55ef3d90bc41cef2a0ae8a7e..717330e86a2b7f46989a3a900d0ccea625422281 100644 (file)
@@ -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) {