本文整理汇总了Golang中github.com/anacrolix/torrent.Torrent.NewReader方法的典型用法代码示例。如果您正苦于以下问题:Golang Torrent.NewReader方法的具体用法?Golang Torrent.NewReader怎么用?Golang Torrent.NewReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/anacrolix/torrent.Torrent
的用法示例。
在下文中一共展示了Torrent.NewReader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: blockingRead
func blockingRead(ctx context.Context, fs *TorrentFS, t torrent.Torrent, off int64, p []byte) (n int, err error) {
fs.mu.Lock()
fs.blockedReads++
fs.event.Broadcast()
fs.mu.Unlock()
var (
_n int
_err error
)
readDone := make(chan struct{})
go func() {
r := t.NewReader()
defer r.Close()
_n, _err = r.ReadAt(p, off)
close(readDone)
}()
select {
case <-readDone:
n = _n
err = _err
case <-fs.destroyed:
err = fuse.EIO
case <-ctx.Done():
err = fuse.EINTR
}
fs.mu.Lock()
fs.blockedReads--
fs.event.Broadcast()
fs.mu.Unlock()
return
}
示例2: blockingRead
func blockingRead(ctx context.Context, fs *TorrentFS, t *torrent.Torrent, off int64, p []byte) (n int, err error) {
fs.mu.Lock()
fs.blockedReads++
fs.event.Broadcast()
fs.mu.Unlock()
var (
_n int
_err error
)
readDone := make(chan struct{})
go func() {
defer close(readDone)
r := t.NewReader()
defer r.Close()
_, _err = r.Seek(off, os.SEEK_SET)
if _err != nil {
return
}
_n, _err = io.ReadFull(r, p)
}()
select {
case <-readDone:
n = _n
err = _err
case <-fs.destroyed:
err = fuse.EIO
case <-ctx.Done():
err = fuse.EINTR
}
fs.mu.Lock()
fs.blockedReads--
fs.event.Broadcast()
fs.mu.Unlock()
return
}
示例3: 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())
}