func Example_fileReader() { var ( t torrent.Torrent f torrent.File ) r := t.NewReader() defer r.Close() // Access the parts of the torrent pertaining to f. Data will be // downloaded as required, per the configuration of the torrent.Reader. _ = missinggo.NewSectionReadSeeker(r, f.Offset(), f.Length()) }
// NewFileReader sets up a torrent file for streaming reading. func NewFileReader(f *torrent.File) (SeekableContent, error) { torrent := f.Torrent() reader := torrent.NewReader() // We read ahead 1% of the file continuously. reader.SetReadahead(f.Length() / 100) reader.SetResponsive() _, err := reader.Seek(f.Offset(), os.SEEK_SET) return &FileEntry{ File: f, Reader: reader, }, err }
// NewFileReader sets up a torrent file for streaming reading. func NewFileReader(c Client, f torrent.File) (SeekableContent, error) { // We read ahead 1% of the file continuously. var readahead = f.Length() / 100 // We begin by prioritizing 5% of the beginning of the file. f.PrioritizeRegion(f.Offset(), readahead*5) reader := c.Torrent.NewReader() reader.SetReadahead(readahead) reader.SetResponsive() _, err := reader.Seek(f.Offset(), os.SEEK_SET) return &FileEntry{ File: &f, Reader: reader, }, err }
// NewFileReader sets up a torrent file for streaming reading. func NewFileReader(f *torrent.File) (SeekableContent, error) { // Start download f.Download() torrent := f.Torrent() reader := torrent.NewReader() // Read ahead 10mb reader.SetReadahead(1024 * 1024 * 10) reader.SetResponsive() _, err := reader.Seek(f.Offset(), os.SEEK_SET) return &FileEntry{ File: f, Reader: reader, N: f.Length(), }, err }