file.go | 17 ++++++++++++++++- diff --git a/file.go b/file.go index f76b99d0823cda8d7fc0a6bba94ce303ef8b68c7..52b5bfeb41bd62a5e666945bb96b925618ed4e5c 100644 --- a/file.go +++ b/file.go @@ -1,6 +1,10 @@ package torrent -import "github.com/anacrolix/torrent/metainfo" +import ( + "strings" + + "github.com/anacrolix/torrent/metainfo" +) // Provides access to regions of torrent data that correspond to its files. type File struct { @@ -26,6 +30,17 @@ } func (f *File) Length() int64 { return f.length +} + +// The relative file path for a multi-file torrent, and the torrent name for a +// single-file torrent. +func (f *File) DisplayPath() string { + fip := f.FileInfo().Path + if len(fip) == 0 { + return f.t.Info().Name + } + return strings.Join(fip, "/") + } type FilePieceState struct {