]> Sergey Matveev's repositories - btrtrc.git/blob - metainfo/fileinfo.go
Add BEP 47 extended file attributes 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         // BEP3. With BEP 47 this can be optional, but we have no way to describe that without breaking
8         // the API.
9         Length   int64    `bencode:"length"`
10         Path     []string `bencode:"path"` // BEP3
11         PathUtf8 []string `bencode:"path.utf-8,omitempty"`
12
13         ExtendedFileAttrs
14 }
15
16 func (fi *FileInfo) DisplayPath(info *Info) string {
17         if info.IsDir() {
18                 return strings.Join(fi.BestPath(), "/")
19         } else {
20                 return info.BestName()
21         }
22 }
23
24 func (me FileInfo) Offset(info *Info) (ret int64) {
25         for _, fi := range info.UpvertedFiles() {
26                 if me.DisplayPath(info) == fi.DisplayPath(info) {
27                         return
28                 }
29                 ret += fi.Length
30         }
31         panic("not found")
32 }
33
34 func (fi FileInfo) BestPath() []string {
35         if len(fi.PathUtf8) != 0 {
36                 return fi.PathUtf8
37         }
38         return fi.Path
39 }