From fe9d5702f64cefd68e36ea9f7544f55bb1fc1b8a Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 18 Jan 2016 20:12:51 +1100 Subject: [PATCH] Fixes for torrent.Reader not having ReadAt --- cmd/torrent-pick/main.go | 3 ++- fs/torrentfs.go | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/torrent-pick/main.go b/cmd/torrent-pick/main.go index 928f11f4..c41e1a07 100644 --- a/cmd/torrent-pick/main.go +++ b/cmd/torrent-pick/main.go @@ -15,6 +15,7 @@ import ( "time" _ "github.com/anacrolix/envpprof" + "github.com/anacrolix/missinggo" "github.com/dustin/go-humanize" "github.com/jessevdk/go-flags" @@ -165,7 +166,7 @@ func main() { if file.DisplayPath() != rootGroup.Pick { continue } - srcReader := io.NewSectionReader(t.NewReader(), file.Offset(), file.Length()) + srcReader := missinggo.NewSectionReadSeeker(t.NewReader(), file.Offset(), file.Length()) io.Copy(dstWriter, srcReader) return } diff --git a/fs/torrentfs.go b/fs/torrentfs.go index 9b3f3958..06dbae55 100644 --- a/fs/torrentfs.go +++ b/fs/torrentfs.go @@ -3,6 +3,7 @@ package torrentfs import ( "expvar" "fmt" + "io" "os" "path" "strings" @@ -82,7 +83,11 @@ func blockingRead(ctx context.Context, fs *TorrentFS, t torrent.Torrent, off int go func() { r := t.NewReader() defer r.Close() - _n, _err = r.ReadAt(p, off) + _, _err = r.Seek(off, os.SEEK_SET) + if _err != nil { + return + } + _n, _err = io.ReadFull(r, p) close(readDone) }() select { -- 2.48.1