Q: Why should io.ReadAll be avoided? I have read some articles on avoiding io.ReadAll and preferring io.Copy over that. They mainly justify this suggestion by mentioning that io.ReadAll loads the whole []byte out of the reader into the memory at once while io.Copy has a fixed buffer which it uses for reading data. But here's the question:
Assuming that I am reading the body of an Http Response which is of type io.ReadCloser. And assuming that the output isn't in JSON and it is a RAW binary response. There are two ways to read the content
var buffer bytes.Buffer 
_, err := io.Copy(&buffer, res.Body) 
// assuming we checked for error
return buffer.Bytes()
--
bytes, err := io.ReadAll(res.Body)
// assuming we checked for error
return bytes

Now what's the difference between the two. I believe that since I am returning the read bytes, the two approaches are identical. I would like to know if the io.Copy approach has any advantage over the other approach in this case at all.

A: This is not an answer since I prefer ReadAll to Copy, but rather an extended comment.
I created 16 MiB (16777216 bytes) sample.txt file and used it for benchmark:
func BenchmarkReadAll(b *testing.B) {
    for i := 0; i < b.N; i++ {
        in, _ := os.Open("sample.txt")
        io.ReadAll(in)
        in.Close()
    }
}

func BenchmarkCopy(b *testing.B) {
    for i := 0; i < b.N; i++ {
        buf := &bytes.Buffer{}
        in, _ := os.Open("sample.txt")
        io.Copy(buf, in)
        in.Close()
    }
}

Output:
goos: linux
goarch: amd64
pkg: example.org
cpu: Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz
BenchmarkReadAll-32           26      45445764 ns/op    102635996 B/op        43 allocs/op
BenchmarkXxx-32               48      23985133 ns/op    67108544 B/op         21 allocs/op

ReadAll has more allocations and, as a result, it consumes more memory in reallocations: to read 16 MiB it allocated/reallocated back and forth 102 MB, 50% more compared to Copy.
Still I prefer ReadAll for its self-explanatory name. On small files better  name beats lesser performance.
