write.go (659B)
1 package iotools 2 3 import "io" 4 5 // WriterFunc is a function signature which allows 6 // a function to implement the io.Writer type. 7 type WriterFunc func([]byte) (int, error) 8 9 func (w WriterFunc) Write(b []byte) (int, error) { 10 return w(b) 11 } 12 13 // WriteCloser wraps an io.Writer and io.Closer in order to implement io.WriteCloser. 14 func WriteCloser(w io.Writer, c io.Closer) io.WriteCloser { 15 return &struct { 16 io.Writer 17 io.Closer 18 }{w, c} 19 } 20 21 // NopWriteCloser wraps an io.Writer to implement io.WriteCloser with empty io.Closer implementation. 22 func NopWriteCloser(w io.Writer) io.WriteCloser { 23 return WriteCloser(w, CloserFunc(func() error { 24 return nil 25 })) 26 }