5 // NopWriter represents a type which write operation is nop.
6 type NopWriter struct{}
8 func (*NopWriter) Write(buf []byte) (int, error) {
12 type nopWriteCloser struct {
16 func (w *nopWriteCloser) Close() error { return nil }
18 // NopWriteCloser returns a nopWriteCloser.
19 func NopWriteCloser(w io.Writer) io.WriteCloser {
20 return &nopWriteCloser{w}
23 // NopFlusher represents a type which flush operation is nop.
24 type NopFlusher struct{}
26 // Flush is a nop operation.
27 func (f *NopFlusher) Flush() {}
29 type writeCloserWrapper struct {
34 func (r *writeCloserWrapper) Close() error {
38 // NewWriteCloserWrapper returns a new io.WriteCloser.
39 func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser {
40 return &writeCloserWrapper{
46 // WriteCounter wraps a concrete io.Writer and hold a count of the number
47 // of bytes written to the writer during a "session".
48 // This can be convenient when write return is masked
49 // (e.g., json.Encoder.Encode())
50 type WriteCounter struct {
55 // NewWriteCounter returns a new WriteCounter.
56 func NewWriteCounter(w io.Writer) *WriteCounter {
62 func (wc *WriteCounter) Write(p []byte) (count int, err error) {
63 count, err = wc.Writer.Write(p)
64 wc.Count += int64(count)