forked from qjfoidnh/BaiduPCS-Go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
multi.go
71 lines (62 loc) · 1.37 KB
/
multi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package rio
import (
"io"
)
// MultiReaderLen 合并多个ReaderLen
func MultiReaderLen(readerLens ...ReaderLen) ReaderLen {
// TODO: 和copy对比
r := make([]io.Reader, 0, len(readerLens))
for k := range readerLens {
if readerLens[k] == nil {
continue
}
r = append(r, readerLens[k])
}
return &multiReaderLen{
mrls: readerLens,
multiReader: io.MultiReader(r...),
}
}
type multiReaderLen struct {
mrls []ReaderLen
multiReader io.Reader
}
func (mrl *multiReaderLen) Read(p []byte) (n int, err error) {
return mrl.multiReader.Read(p)
}
func (mrl *multiReaderLen) Len() int {
var i int
for k := range mrl.mrls {
i += mrl.mrls[k].Len()
}
return i
}
// MultiReaderLen64 合并多个ReaderLen64
func MultiReaderLen64(readerLen64s ...ReaderLen64) ReaderLen64 {
// TODO: 和copy对比
r := make([]io.Reader, 0, len(readerLen64s))
for k := range readerLen64s {
if readerLen64s[k] == nil {
continue
}
r = append(r, readerLen64s[k])
}
return &multiReaderLen64{
mrl64s: readerLen64s,
multiReader: io.MultiReader(r...),
}
}
type multiReaderLen64 struct {
mrl64s []ReaderLen64
multiReader io.Reader
}
func (mrl64 *multiReaderLen64) Read(p []byte) (n int, err error) {
return mrl64.multiReader.Read(p)
}
func (mrl64 *multiReaderLen64) Len() int64 {
var l int64
for k := range mrl64.mrl64s {
l += mrl64.mrl64s[k].Len()
}
return l
}