Standard library / io
io.LimitedReader.Read()
Reads at most the remaining N bytes and decreases N by bytes actually read; returns EOF when N is exhausted. Expected stdout: '2 ab 0 <nil>\n'.
Formal Syntax & Structure
go syntaxgo
func (l *LimitedReader) Read(p []byte) (n int, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| p | []byte | Byte slice supplied by the caller. |
Return Value
(n int, err error)
Reads at most the remaining N bytes and decreases N by bytes actually read; returns EOF when N is exhausted.
Working Example
Example Snippetgo
package main
import ( "fmt" "io" "strings")
func main() { r := &io.LimitedReader{R: strings.NewReader("abc"), N: 2} b := make([]byte, 4) n, e := r.Read(b) fmt.Println(n, string(b[:n]), r.N, e)}