6 "github.com/anacrolix/torrent/metainfo"
9 // Provides access to regions of torrent data that correspond to its files.
18 func (f *File) Torrent() Torrent {
22 // Data for this file begins this far into the torrent.
23 func (f *File) Offset() int64 {
27 func (f File) FileInfo() metainfo.FileInfo {
31 func (f File) Path() string {
35 func (f *File) Length() int64 {
39 // The relative file path for a multi-file torrent, and the torrent name for a
40 // single-file torrent.
41 func (f *File) DisplayPath() string {
42 fip := f.FileInfo().Path
44 return f.t.Info().Name
46 return strings.Join(fip, "/")
50 type FilePieceState struct {
51 Bytes int64 // Bytes within the piece that are part of this File.
55 // Returns the state of pieces in this file.
56 func (f *File) State() (ret []FilePieceState) {
57 pieceSize := int64(f.t.torrent.usualPieceSize())
58 off := f.offset % pieceSize
60 for i := int(f.offset / pieceSize); ; i++ {
64 len1 := pieceSize - off
69 ps := f.t.torrent.pieceState(i)
71 ret = append(ret, FilePieceState{len1, ps})
78 func (f *File) Download() {
79 f.t.DownloadPieces(f.t.torrent.byteRegionPieces(f.offset, f.length))