Standard library / io
io.OffsetWriter
Adapter for writing to a WriterAt with a base offset and sequential cursor; use NewOffsetWriter. Expected stdout: '.a.\n'.
Formal Syntax & Structure
go syntaxgo
type OffsetWriter struct { /* unexported fields */ }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() { m := &memory{data: []byte("...")} var w *io.OffsetWriter = io.NewOffsetWriter(m, 1) w.Write([]byte("a")) fmt.Println(string(m.data))}