this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/source: simplify ReadAll

It's unclear to me why we were rolling our own version of io.ReadAll;
the standard library function already does what we need here.

While here, remove the nil check on *bytes.Buffer.
If a user sets cue/build.File.Source to (*bytes.Buffer)(nil),
that seems like a bug that should result in a panic
rather than silently reading zero bytes.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I636d3f43c7085a8b94ffd7541504324ee83250dd
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1225201
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+2 -8
+2 -8
internal/source/source.go
··· 37 37 return src, nil 38 38 case *bytes.Buffer: 39 39 // is io.Reader, but src is already available in []byte form 40 - if src != nil { 41 - return src.Bytes(), nil 42 - } 40 + return src.Bytes(), nil 43 41 case io.Reader: 44 - var buf bytes.Buffer 45 - if _, err := io.Copy(&buf, src); err != nil { 46 - return nil, err 47 - } 48 - return buf.Bytes(), nil 42 + return io.ReadAll(src) 49 43 } 50 44 return nil, fmt.Errorf("invalid source type %T", src) 51 45 }