1 Star 0 Fork 1

freely随意/BaiduPCS-Go

forked from ttpc2008/BaiduPCS-Go 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
multi.go 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/freelysuiyi/BaiduPCS-Go.git
git@gitee.com:freelysuiyi/BaiduPCS-Go.git
freelysuiyi
BaiduPCS-Go
BaiduPCS-Go
v3.5.5

搜索帮助

0d507c66 1850385 C8b1a773 1850385