Standard library / bytes
bytes.Reader.Seek()
Changes byte position relative to start, current cursor or end. Negative resulting offsets and invalid whence fail; seeking beyond end is allowed. Expected stdout: '1 <nil> 2\n'.
Formal Syntax & Structure
go syntaxgo
func (r *Reader) Seek(offset int64, whence int) (int64, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| offset | int64 | Signed byte displacement relative to whence. |
| whence | int | Origin: io.SeekStart, io.SeekCurrent or io.SeekEnd. |
Return Value
(int64, error)
Changes byte position relative to start, current cursor or end. Negative resulting offsets and invalid whence fail; seeking beyond end is allowed.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "io")
func main() { r := bytes.NewReader([]byte("aé")) pos, e := r.Seek(-2, io.SeekEnd) fmt.Println(pos, e, r.Len())}