]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fixes for torrent.Reader not having ReadAt
authorMatt Joiner <anacrolix@gmail.com>
Mon, 18 Jan 2016 09:12:51 +0000 (20:12 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 18 Jan 2016 09:12:51 +0000 (20:12 +1100)
cmd/torrent-pick/main.go
fs/torrentfs.go

index 928f11f4df00d16b0f7832c1e8ae7ac69e2ead54..c41e1a073f675b6bbb279e456a14a1446a16c315 100644 (file)
@@ -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
                        }
index 9b3f3958768532a1497d9befbd450a4ba2d64928..06dbae558815c7051ec6206db52d68560ff98004 100644 (file)
@@ -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 {