mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-25 09:54:47 +01:00
35 lines
539 B
Go
35 lines
539 B
Go
package chainedio
|
|
|
|
import "io"
|
|
|
|
type ChainedReader struct {
|
|
Readers []io.Reader
|
|
curReader int
|
|
}
|
|
|
|
func NewChainedReader(reader ...io.Reader) *ChainedReader {
|
|
return &ChainedReader{
|
|
Readers: reader,
|
|
curReader: 0,
|
|
}
|
|
}
|
|
|
|
func (c *ChainedReader) Read(buf []byte) (n int, err error) {
|
|
|
|
n = 0
|
|
|
|
for c.curReader < len(c.Readers) {
|
|
n, err = c.Readers[c.curReader].Read(buf)
|
|
if err == io.EOF {
|
|
c.curReader++
|
|
continue
|
|
}
|
|
break
|
|
}
|
|
if c.curReader == len(c.Readers) {
|
|
err = io.EOF // actually, there was no gap
|
|
}
|
|
|
|
return
|
|
}
|