golang standard library --io

一、type Reader interface {

    Read(p []byte)(n int, err error)

  }

  Reader is an interface that contains the Read method

  Read method reads len (p) of the byte to p. It returns the number of bytes to read, and errors encountered. Even Read Back n <len (p), p is also used as a temporary storage space for all during the call. If some of the data can be read no len (p), by convention Read will return to read the data, rather than waiting for more.

  Read successfully read after n> 0 bytes encountered an error or end-of-file condition, it returns the number of bytes to read. It will return a non-null error from the same call or return an error from the next call, and n == 0. A common example of this case is: a Reader returns a nonzero number of bytes at the end of the input stream is returned err == EOF or err == nil. The next Read will return 0, EOF.

  n> 0 bytes before the caller should always be considered before handling error is returned, do it properly processing occurs after reading some bytes and both allow EOF behavior of I / O error

  Read implement this interface should not return 0 bytes error and nil, unless len (p) == 0. The caller should treat this situation Why did not happen, it does not mean special attention to the reading end.

  Read implementation must not return p

two,

  

Guess you like

Origin www.cnblogs.com/DjanFey/p/12288410.html
Recommended