本文整理汇总了Golang中github.com/anacrolix/torrent.File类的典型用法代码示例。如果您正苦于以下问题:Golang File类的具体用法?Golang File怎么用?Golang File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Example_fileReader
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())
}
示例2: NewFileReader
// 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
reader := c.Torrent.NewReader()
reader.SetReadahead(readahead)
reader.SetResponsive()
_, err := reader.Seek(f.Offset(), os.SEEK_SET)
return &FileEntry{
File: f,
Reader: reader,
}, err
}
示例3: NewFileReader
// 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
}
示例4: DownloadPlay
func (this *DownloaderService) DownloadPlay(downloader_id, file_path string) (sc SeekAbleContent, path string, err error) {
log.Println("DownloadPlay: downloader_id -> ", downloader_id, " file_path -> ", file_path)
this.RLock()
defer this.RUnlock()
var downloader = &downloader.Downloader{}
var file torrent.File
downloader, err = this.df.Get(downloader_id)
if err != nil {
return
}
file, err = downloader.GetFileFoPlay(file_path)
if err != nil {
return
}
sc, err = NewReader(downloader.Torrent, file)
if err != nil {
return
}
return sc, file.DisplayPath(), nil
}
示例5: NewFileReader
// 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
}
示例6: GetTorrentPercent
func (e *Engine) GetTorrentPercent(file *torrent.File) float32 {
t := e.upsertTorrent(file.Torrent())
return t.Percent
}