Standard library / io

io.OffsetWriter.Seek()

Sets or changes the relative write offset. SeekEnd is unsupported because the underlying WriterAt exposes no size. Expected stdout: '2 <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func (o *OffsetWriter) Seek(offset int64, whence int) (int64, error)

Parameters & Attributes

NameTypeDescription
offsetint64Signed seek displacement.
whenceintSeek origin, one of the io.Seek constants.

Return Value

(int64, error)

Sets or changes the relative write offset.

Working Example

Example Snippetgo
package main
import (  "fmt"  "io")
type memory struct{ data []byte }
func (m *memory) WriteAt(p []byte, off int64) (int, error) {  if off < 0 || off >= int64(len(m.data)) {    return 0, io.ErrShortWrite  }  n := copy(m.data[int(off):], p)  if n < len(p) {    return n, io.ErrShortWrite  }  return n, nil}func main() {  w := io.NewOffsetWriter(&memory{data: make([]byte, 5)}, 1)  n, e := w.Seek(2, io.SeekStart)  fmt.Println(n, e)}
Go Reference