1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/common/buf/merge_reader.go
Darien Raymond f506a39d32
multi buffer
2017-04-15 21:07:23 +02:00

35 lines
535 B
Go

package buf
type MergingReader struct {
reader Reader
timeoutReader TimeoutReader
}
func NewMergingReader(reader Reader) Reader {
return &MergingReader{
reader: reader,
timeoutReader: reader.(TimeoutReader),
}
}
func (r *MergingReader) Read() (MultiBuffer, error) {
mb, err := r.reader.Read()
if err != nil {
return nil, err
}
if r.timeoutReader == nil {
return mb, nil
}
for {
mb2, err := r.timeoutReader.ReadTimeout(0)
if err != nil {
break
}
mb.AppendMulti(mb2)
}
return mb, nil
}