]> Sergey Matveev's repositories - btrtrc.git/blob - storage/file-misc.go
Remove torrentfs-macos job from CI
[btrtrc.git] / storage / file-misc.go
1 package storage
2
3 import "github.com/anacrolix/torrent/metainfo"
4
5 type requiredLength struct {
6         fileIndex int
7         length    int64
8 }
9
10 func extentCompleteRequiredLengths(info *metainfo.Info, off, n int64) (ret []requiredLength) {
11         if n == 0 {
12                 return
13         }
14         for i, fi := range info.UpvertedFiles() {
15                 if off >= fi.Length {
16                         off -= fi.Length
17                         continue
18                 }
19                 n1 := n
20                 if off+n1 > fi.Length {
21                         n1 = fi.Length - off
22                 }
23                 ret = append(ret, requiredLength{
24                         fileIndex: i,
25                         length:    off + n1,
26                 })
27                 n -= n1
28                 if n == 0 {
29                         return
30                 }
31                 off = 0
32         }
33         panic("extent exceeds torrent bounds")
34 }