Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does io.WriterTo's WriteTo method return an int64 rather than an int?

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?

like image 613
Matt Avatar asked Apr 15 '15 19:04

Matt


1 Answers

It's possible that WriteTo copies more than int32 bytes of data.

With the io.Readerand 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.

like image 83
JimB Avatar answered Oct 18 '22 10:10

JimB