Standard library / bytes
bytes.Reader.ReadAt()
Reads from a byte offset without changing the cursor. Returns non-nil error when fewer than len(b) bytes are read. Expected stdout: '2 <nil> é 3\n'.
Formal Syntax & Structure
go syntaxgo
func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| b | []byte | Writable destination slice; its length limits bytes read. |
| off | int64 | Absolute byte offset at which to read. |
Return Value
(n int, err error)
Reads from a byte offset without changing the cursor. Returns non-nil error when fewer than len(b) bytes are read.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt")
func main() { r := bytes.NewReader([]byte("aé")) b := make([]byte, 2) n, e := r.ReadAt(b, 1) fmt.Println(n, e, string(b), r.Len())}