]> Sergey Matveev's repositories - btrtrc.git/blob - metainfo/fileinfo.go
cmd/btrtrc client
[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         // Unofficial extension by BiglyBT? https://github.com/BiglySoftware/BiglyBT/issues/1274. Might
16         // be a safer bet when available: https://github.com/anacrolix/torrent/pull/915.
17         PathUtf8 []string `bencode:"path.utf-8,omitempty"`
18
19         ExtendedFileAttrs
20
21         // BEP 52. This isn't encoded in a v1 FileInfo, but is exposed here for APIs that expect to deal
22         // v1 files.
23         PiecesRoot    g.Option[[32]byte] `bencode:"-"`
24         TorrentOffset int64              `bencode:"-"`
25 }
26
27 func (fi *FileInfo) DisplayPath(info *Info) string {
28         if info.IsDir() {
29                 return strings.Join(fi.BestPath(), "/")
30         } else {
31                 return info.BestName()
32         }
33 }
34
35 func (fi *FileInfo) BestPath() []string {
36         if len(fi.PathUtf8) != 0 {
37                 return fi.PathUtf8
38         }
39         return fi.Path
40 }