github.com/yandex/pandora@v0.5.32/lib/ioutil2/writer.go (about)

     1  package ioutil2
     2  
     3  import (
     4  	"bufio"
     5  	"bytes"
     6  	"io"
     7  )
     8  
     9  type StringWriter interface {
    10  	WriteString(s string) (n int, err error)
    11  }
    12  
    13  // ByteWriter represents efficient io.Writer, that don't need buffering.
    14  // Implemented by *bufio.Writer and *bytes.Buffer.
    15  type ByteWriter interface {
    16  	io.Writer
    17  	StringWriter
    18  	io.ByteWriter
    19  	io.ReaderFrom
    20  }
    21  
    22  var _ ByteWriter = &bufio.Writer{}
    23  var _ ByteWriter = &bytes.Buffer{}
    24  
    25  func NewCallbackWriter(w io.Writer, onWrite func()) WriterFunc {
    26  	return func(p []byte) (n int, err error) {
    27  		onWrite()
    28  		return w.Write(p)
    29  	}
    30  }