]> Sergey Matveev's repositories - btrtrc.git/blob - metainfo/fileinfo.go
Add comments to metainfo.Magnet fields
[btrtrc.git] / metainfo / fileinfo.go
1 package metainfo
2
3 import "strings"
4
5 // Information specific to a single file inside the MetaInfo structure.
6 type FileInfo struct {
7         Length int64    `bencode:"length"`
8         Path   []string `bencode:"path"`
9 }
10
11 func (fi *FileInfo) DisplayPath(info *Info) string {
12         if info.IsDir() {
13                 return strings.Join(fi.Path, "/")
14         } else {
15                 return info.Name
16         }
17 }
18
19 func (me FileInfo) Offset(info *Info) (ret int64) {
20         for _, fi := range info.UpvertedFiles() {
21                 if me.DisplayPath(info) == fi.DisplayPath(info) {
22                         return
23                 }
24                 ret += fi.Length
25         }
26         panic("not found")
27 }