2016-07-10 21:03:59 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import "github.com/anacrolix/torrent/metainfo"
|
|
|
|
|
2020-10-15 12:45:08 +08:00
|
|
|
type requiredLength struct {
|
|
|
|
fileIndex int
|
|
|
|
length int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func extentCompleteRequiredLengths(info *metainfo.Info, off, n int64) (ret []requiredLength) {
|
2016-07-10 21:03:59 +08:00
|
|
|
if n == 0 {
|
|
|
|
return
|
|
|
|
}
|
2020-10-15 12:45:08 +08:00
|
|
|
for i, fi := range info.UpvertedFiles() {
|
2016-07-10 21:03:59 +08:00
|
|
|
if off >= fi.Length {
|
|
|
|
off -= fi.Length
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
n1 := n
|
|
|
|
if off+n1 > fi.Length {
|
|
|
|
n1 = fi.Length - off
|
|
|
|
}
|
2020-10-15 12:45:08 +08:00
|
|
|
ret = append(ret, requiredLength{
|
|
|
|
fileIndex: i,
|
|
|
|
length: off + n1,
|
2016-07-10 21:03:59 +08:00
|
|
|
})
|
|
|
|
n -= n1
|
|
|
|
if n == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
off = 0
|
|
|
|
}
|
|
|
|
panic("extent exceeds torrent bounds")
|
|
|
|
}
|