]> Sergey Matveev's repositories - btrtrc.git/blob - metainfo/fileinfo.go
use path.utf8 first for some torrent (#350)
[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         PathUTF8 []string `bencode:"path.utf-8,omitempty"`
10 }
11
12 func (fi *FileInfo) DisplayPath(info *Info) string {
13         if info.IsDir() {
14                 return strings.Join(fi.Path, "/")
15         } else {
16                 return info.Name
17         }
18 }
19
20 func (me FileInfo) Offset(info *Info) (ret int64) {
21         for _, fi := range info.UpvertedFiles() {
22                 if me.DisplayPath(info) == fi.DisplayPath(info) {
23                         return
24                 }
25                 ret += fi.Length
26         }
27         panic("not found")
28 }