Extract common Torrent.newReader
This commit is contained in:
parent
3c95512f23
commit
4912ae2781
10
file.go
10
file.go
@ -140,15 +140,7 @@ func (f *File) Cancel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *File) NewReader() Reader {
|
func (f *File) NewReader() Reader {
|
||||||
tr := reader{
|
return f.t.newReader(f.Offset(), f.Length())
|
||||||
mu: f.t.cl.locker(),
|
|
||||||
t: f.t,
|
|
||||||
readahead: 5 * 1024 * 1024,
|
|
||||||
offset: f.Offset(),
|
|
||||||
length: f.Length(),
|
|
||||||
}
|
|
||||||
f.t.addReader(&tr)
|
|
||||||
return &tr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the minimum priority for pieces in the File.
|
// Sets the minimum priority for pieces in the File.
|
||||||
|
7
t.go
7
t.go
@ -32,11 +32,16 @@ func (t *Torrent) Info() *metainfo.Info {
|
|||||||
// Returns a Reader bound to the torrent's data. All read calls block until the data requested is
|
// Returns a Reader bound to the torrent's data. All read calls block until the data requested is
|
||||||
// actually available. Note that you probably want to ensure the Torrent Info is available first.
|
// actually available. Note that you probably want to ensure the Torrent Info is available first.
|
||||||
func (t *Torrent) NewReader() Reader {
|
func (t *Torrent) NewReader() Reader {
|
||||||
|
return t.newReader(0, *t.length)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Torrent) newReader(offset, length int64) Reader {
|
||||||
r := reader{
|
r := reader{
|
||||||
mu: t.cl.locker(),
|
mu: t.cl.locker(),
|
||||||
t: t,
|
t: t,
|
||||||
readahead: 5 * 1024 * 1024,
|
readahead: 5 * 1024 * 1024,
|
||||||
length: *t.length,
|
offset: offset,
|
||||||
|
length: length,
|
||||||
}
|
}
|
||||||
t.addReader(&r)
|
t.addReader(&r)
|
||||||
return &r
|
return &r
|
||||||
|
Loading…
x
Reference in New Issue
Block a user