reader.go | 7 ++++--- diff --git a/reader.go b/reader.go index 1b3815f3bdc6a77fa8330f09131131316eda3e11..72c94881e5659b9f91e6ff020bdb118efdff3b39 100644 --- a/reader.go +++ b/reader.go @@ -5,6 +5,8 @@ "errors" "io" "os" "sync" + + "github.com/anacrolix/missinggo" ) // Accesses torrent data via a client. @@ -148,11 +150,10 @@ b1 := b[:avail] pi := int(pos / r.t.Info().PieceLength) ip := r.t.Info().Piece(pi) po := pos % ip.Length() - if int64(len(b1)) > ip.Length()-po { - b1 = b1[:ip.Length()-po] - } + missinggo.LimitLen(&b1, ip.Length()-po) n, err = r.t.torrent.readAt(b1, pos) if n != 0 { + err = nil return } // log.Printf("%s: error reading from torrent storage pos=%d: %s", r.t, pos, err)