Most of the output methods in Go's io
package return (int, error)
, for example io.Writer
's Write([]byte)
method and the io.WriteString(io.Writer, string)
function. However, a few of the output methods, such as io.WriterTo
's WriteTo
method, return (int64, error)
instead. This makes it inconvenient to implement WriteTo
in terms of Write
or WriteString
without storing an intermediate value and type converting it from int
to int64
. What is the reason for this discrepancy?
It's possible that WriteTo
copies more than int32 bytes of data.
With the io.Reader
and io.Writer
interfaces, the amount of data is limited by the size of the given slice, which has a length limited by int
for the current architecture.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With