Standard library / io

io.WriteSeeker

Combines Writer and Seeker for repositionable output; interface alone does not specify file durability. Expected stdout: 'contract satisfied\n'.

Formal Syntax & Structure

go syntaxgo
type WriteSeeker interface {  Writer  Seeker}

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() {  var _ io.WriteSeeker = io.NewOffsetWriter(&memory{data: make([]byte, 4)}, 0)  fmt.Println("contract satisfied")}
Go Reference