Reads up to p.byteLength bytes into p. It resolves to the number
of bytes read (0 <= n <= p.byteLength) and any error encountered.
Even if read() returns n < p.byteLength, it may use all of p as
scratch space during the call. If some data is available but not
p.byteLength bytes, read() conventionally returns what is available
instead of waiting for more.
When read() encounters an error or end-of-file condition after
successfully reading n > 0 bytes, it returns the number of bytes read.
It may return the (non-nil) error from the same call or return the error
(and n == 0) from a subsequent call. An instance of this general case
is that a Reader returning a non-zero number of bytes at the end of the
input stream may return either err == EOF or err == null. The next
read() should return 0, EOF.
Callers should always process the n > 0 bytes returned before
considering the EOF. Doing so correctly handles I/O errors that happen
after reading some bytes and also both of the allowed EOF behaviors.
Implementations of read() are discouraged from returning a zero byte
count with a null error, except when p.byteLength == 0. Callers
should treat a return of 0 and null as indicating that nothing
happened; in particular it does not indicate EOF.
Reads up to p.byteLength bytes into
p
. It resolves to the number of bytes read (0
<=n
<=p.byteLength
) and any error encountered. Even ifread()
returnsn
<p.byteLength
, it may use all ofp
as scratch space during the call. If some data is available but notp.byteLength
bytes,read()
conventionally returns what is available instead of waiting for more.When
read()
encounters an error or end-of-file condition after successfully readingn
>0
bytes, it returns the number of bytes read. It may return the (non-nil) error from the same call or return the error (andn
==0
) from a subsequent call. An instance of this general case is that aReader
returning a non-zero number of bytes at the end of the input stream may return eithererr
==EOF
orerr
==null
. The nextread()
should return0
,EOF
.Callers should always process the
n
>0
bytes returned before considering theEOF
. Doing so correctly handles I/O errors that happen after reading some bytes and also both of the allowedEOF
behaviors.Implementations of
read()
are discouraged from returning a zero byte count with anull
error, except whenp.byteLength
==0
. Callers should treat a return of0
andnull
as indicating that nothing happened; in particular it does not indicateEOF
.Implementations must not retain
p
.