From 6a8bbc4e14bfa095da458f23614a0972862f3588 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 3 Apr 2016 16:35:28 +1000 Subject: [PATCH] Suppress piece read errors when data is obtained --- reader.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/reader.go b/reader.go index 1b3815f3..72c94881 100644 --- a/reader.go +++ b/reader.go @@ -5,6 +5,8 @@ import ( "io" "os" "sync" + + "github.com/anacrolix/missinggo" ) // Accesses torrent data via a client. @@ -148,11 +150,10 @@ func (r *Reader) readOnceAt(b []byte, pos int64) (n int, err error) { 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) -- 2.48.1