Standard library / strings

strings.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

NameTypeDescription
b[]byteWritable destination slice; its length limits bytes read.
offint64Absolute 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 (  "fmt"  "strings")
func main() {  r := strings.NewReader("aé")  b := make([]byte, 2)  n, e := r.ReadAt(b, 1)  fmt.Println(n, e, string(b), r.Len())}
Go Reference