2
0
mirror of synced 2025-02-23 14:18:13 +00:00

Extract common Torrent.newReader

This commit is contained in:
Matt Joiner 2021-09-09 17:41:12 +10:00
parent 3c95512f23
commit 4912ae2781
2 changed files with 7 additions and 10 deletions

10
file.go
View File

@ -140,15 +140,7 @@ func (f *File) Cancel() {
}
func (f *File) NewReader() Reader {
tr := reader{
mu: f.t.cl.locker(),
t: f.t,
readahead: 5 * 1024 * 1024,
offset: f.Offset(),
length: f.Length(),
}
f.t.addReader(&tr)
return &tr
return f.t.newReader(f.Offset(), f.Length())
}
// Sets the minimum priority for pieces in the File.

7
t.go
View File

@ -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
// actually available. Note that you probably want to ensure the Torrent Info is available first.
func (t *Torrent) NewReader() Reader {
return t.newReader(0, *t.length)
}
func (t *Torrent) newReader(offset, length int64) Reader {
r := reader{
mu: t.cl.locker(),
t: t,
readahead: 5 * 1024 * 1024,
length: *t.length,
offset: offset,
length: length,
}
t.addReader(&r)
return &r