Standard library / io
io.ReadFull()
Fills the entire buffer or reports EOF or ErrUnexpectedEOF. Use for fixed-size headers. Expected stdout: '3 abc <nil>\n'.
Formal Syntax & Structure
go syntaxgo
func ReadFull(r Reader, buf []byte) (n int, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| r | Reader | Source reader. |
| buf | []byte | Caller-supplied byte buffer. |
Return Value
(n int, err error)
Fills the entire buffer or reports EOF or ErrUnexpectedEOF.
Working Example
Example Snippetgo
package main
import ( "fmt" "io" "strings")
func main() { b := make([]byte, 3) n, e := io.ReadFull(strings.NewReader("abcd"), b) fmt.Println(n, string(b), e)}