diff --git a/common/buf/reader.go b/common/buf/reader.go index 124e3e3a..632a0039 100644 --- a/common/buf/reader.go +++ b/common/buf/reader.go @@ -58,21 +58,16 @@ var ( ) type BufferedReader struct { - stream Reader - legacyReader io.Reader - leftOver MultiBuffer - buffered bool + stream Reader + leftOver MultiBuffer + buffered bool } func NewBufferedReader(reader Reader) *BufferedReader { - r := &BufferedReader{ + return &BufferedReader{ stream: reader, buffered: true, } - if lr, ok := reader.(io.Reader); ok { - r.legacyReader = lr - } - return r } func (r *BufferedReader) SetBuffered(f bool) { @@ -99,8 +94,10 @@ func (r *BufferedReader) Read(b []byte) (int, error) { return nBytes, nil } - if !r.buffered && r.legacyReader != nil { - return r.legacyReader.Read(b) + if !r.buffered { + if reader, ok := r.stream.(io.Reader); ok { + return reader.Read(b) + } } mb, err := r.stream.ReadMultiBuffer() diff --git a/common/buf/writer.go b/common/buf/writer.go index a6bada13..6dbc886e 100644 --- a/common/buf/writer.go +++ b/common/buf/writer.go @@ -48,23 +48,18 @@ var ( // BufferedWriter is a Writer with internal buffer. type BufferedWriter struct { - writer Writer - legacyWriter io.Writer - buffer *Buffer - buffered bool + writer Writer + buffer *Buffer + buffered bool } // NewBufferedWriter creates a new BufferedWriter. func NewBufferedWriter(writer Writer) *BufferedWriter { - w := &BufferedWriter{ + return &BufferedWriter{ writer: writer, buffer: New(), buffered: true, } - if lw, ok := writer.(io.Writer); ok { - w.legacyWriter = lw - } - return w } func (w *BufferedWriter) WriteByte(c byte) error { @@ -74,8 +69,10 @@ func (w *BufferedWriter) WriteByte(c byte) error { // Write implements io.Writer. func (w *BufferedWriter) Write(b []byte) (int, error) { - if !w.buffered && w.legacyWriter != nil { - return w.legacyWriter.Write(b) + if !w.buffered { + if writer, ok := w.writer.(io.Writer); ok { + return writer.Write(b) + } } totalBytes := 0