2
0
mirror of synced 2025-02-24 22:58:28 +00:00
torrent/storage/file_misc.go
Matt Joiner f055abe2fc Fix issue #96
In the native file-based storage, mark pieces incomplete if the necessary file data is missing, or there's a read error on a piece.
2016-07-10 23:03:59 +10:00

30 lines
533 B
Go

package storage
import "github.com/anacrolix/torrent/metainfo"
func extentCompleteRequiredLengths(info *metainfo.Info, off, n int64) (ret []metainfo.FileInfo) {
if n == 0 {
return
}
for _, fi := range info.UpvertedFiles() {
if off >= fi.Length {
off -= fi.Length
continue
}
n1 := n
if off+n1 > fi.Length {
n1 = fi.Length - off
}
ret = append(ret, metainfo.FileInfo{
Path: fi.Path,
Length: off + n1,
})
n -= n1
if n == 0 {
return
}
off = 0
}
panic("extent exceeds torrent bounds")
}