mirror of https://github.com/v2ray/v2ray-core
cleanup
parent
052d2d8278
commit
41961dbd60
|
@ -58,21 +58,16 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type BufferedReader struct {
|
type BufferedReader struct {
|
||||||
stream Reader
|
stream Reader
|
||||||
legacyReader io.Reader
|
leftOver MultiBuffer
|
||||||
leftOver MultiBuffer
|
buffered bool
|
||||||
buffered bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBufferedReader(reader Reader) *BufferedReader {
|
func NewBufferedReader(reader Reader) *BufferedReader {
|
||||||
r := &BufferedReader{
|
return &BufferedReader{
|
||||||
stream: reader,
|
stream: reader,
|
||||||
buffered: true,
|
buffered: true,
|
||||||
}
|
}
|
||||||
if lr, ok := reader.(io.Reader); ok {
|
|
||||||
r.legacyReader = lr
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *BufferedReader) SetBuffered(f bool) {
|
func (r *BufferedReader) SetBuffered(f bool) {
|
||||||
|
@ -99,8 +94,10 @@ func (r *BufferedReader) Read(b []byte) (int, error) {
|
||||||
return nBytes, nil
|
return nBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !r.buffered && r.legacyReader != nil {
|
if !r.buffered {
|
||||||
return r.legacyReader.Read(b)
|
if reader, ok := r.stream.(io.Reader); ok {
|
||||||
|
return reader.Read(b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mb, err := r.stream.ReadMultiBuffer()
|
mb, err := r.stream.ReadMultiBuffer()
|
||||||
|
|
|
@ -48,23 +48,18 @@ var (
|
||||||
|
|
||||||
// BufferedWriter is a Writer with internal buffer.
|
// BufferedWriter is a Writer with internal buffer.
|
||||||
type BufferedWriter struct {
|
type BufferedWriter struct {
|
||||||
writer Writer
|
writer Writer
|
||||||
legacyWriter io.Writer
|
buffer *Buffer
|
||||||
buffer *Buffer
|
buffered bool
|
||||||
buffered bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBufferedWriter creates a new BufferedWriter.
|
// NewBufferedWriter creates a new BufferedWriter.
|
||||||
func NewBufferedWriter(writer Writer) *BufferedWriter {
|
func NewBufferedWriter(writer Writer) *BufferedWriter {
|
||||||
w := &BufferedWriter{
|
return &BufferedWriter{
|
||||||
writer: writer,
|
writer: writer,
|
||||||
buffer: New(),
|
buffer: New(),
|
||||||
buffered: true,
|
buffered: true,
|
||||||
}
|
}
|
||||||
if lw, ok := writer.(io.Writer); ok {
|
|
||||||
w.legacyWriter = lw
|
|
||||||
}
|
|
||||||
return w
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *BufferedWriter) WriteByte(c byte) error {
|
func (w *BufferedWriter) WriteByte(c byte) error {
|
||||||
|
@ -74,8 +69,10 @@ func (w *BufferedWriter) WriteByte(c byte) error {
|
||||||
|
|
||||||
// Write implements io.Writer.
|
// Write implements io.Writer.
|
||||||
func (w *BufferedWriter) Write(b []byte) (int, error) {
|
func (w *BufferedWriter) Write(b []byte) (int, error) {
|
||||||
if !w.buffered && w.legacyWriter != nil {
|
if !w.buffered {
|
||||||
return w.legacyWriter.Write(b)
|
if writer, ok := w.writer.(io.Writer); ok {
|
||||||
|
return writer.Write(b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
totalBytes := 0
|
totalBytes := 0
|
||||||
|
|
Loading…
Reference in New Issue