mirror of https://github.com/v2ray/v2ray-core
cleanup
parent
052d2d8278
commit
41961dbd60
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue