本文整理汇总了Golang中github.com/anacrolix/torrent.File.Length方法的典型用法代码示例。如果您正苦于以下问题:Golang File.Length方法的具体用法?Golang File.Length怎么用?Golang File.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/anacrolix/torrent.File
的用法示例。
在下文中一共展示了File.Length方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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(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
}
示例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: 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
}