]> Sergey Matveev's repositories - btrtrc.git/blob - metainfo/fileinfo.go
Misc improvements
[btrtrc.git] / metainfo / fileinfo.go
1 package metainfo
2
3 import (
4         "strings"
5
6         g "github.com/anacrolix/generics"
7 )
8
9 // Information specific to a single file inside the MetaInfo structure.
10 type FileInfo struct {
11         // BEP3. With BEP 47 this can be optional, but we have no way to describe that without breaking
12         // the API.
13         Length   int64    `bencode:"length"`
14         Path     []string `bencode:"path"` // BEP3
15         PathUtf8 []string `bencode:"path.utf-8,omitempty"`
16
17         ExtendedFileAttrs
18
19         // BEP 52. This isn't encoded in a v1 FileInfo, but is exposed here for APIs that expect to deal
20         // v1 files.
21         PiecesRoot    g.Option[[32]byte] `bencode:"-"`
22         TorrentOffset int64              `bencode:"-"`
23 }
24
25 func (fi *FileInfo) DisplayPath(info *Info) string {
26         if info.IsDir() {
27                 return strings.Join(fi.BestPath(), "/")
28         } else {
29                 return info.BestName()
30         }
31 }
32
33 func (fi *FileInfo) BestPath() []string {
34         if len(fi.PathUtf8) != 0 {
35                 return fi.PathUtf8
36         }
37         return fi.Path
38 }