2017-01-04 14:15:11 +08:00
|
|
|
package metainfo
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
|
|
|
// Information specific to a single file inside the MetaInfo structure.
|
|
|
|
type FileInfo struct {
|
|
|
|
Length int64 `bencode:"length"`
|
|
|
|
Path []string `bencode:"path"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fi *FileInfo) DisplayPath(info *Info) string {
|
|
|
|
if info.IsDir() {
|
|
|
|
return strings.Join(fi.Path, "/")
|
|
|
|
} else {
|
|
|
|
return info.Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (me FileInfo) Offset(info *Info) (ret int64) {
|
2017-01-04 15:09:17 +08:00
|
|
|
for _, fi := range info.UpvertedFiles() {
|
2017-01-04 14:15:11 +08:00
|
|
|
if me.DisplayPath(info) == fi.DisplayPath(info) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ret += fi.Length
|
|
|
|
}
|
|
|
|
panic("not found")
|
|
|
|
}
|