Golang bytes.Reader.ReadAt() function example

package bytes

Golang bytes.Reader.ReadAt() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {

 reader := bytes.NewReader([]byte("abc"))

 var b [3]byte
 n, err := reader.ReadAt(b[:], 2) // start reading at offset/position 2

 // should print the character c
 fmt.Printf("%d %v %s \n", n, err, string(b[:]))

 }

Output :

1 EOF c

Reference :

http://golang.org/pkg/bytes/#Reader.ReadAt

Advertisement