torrent.go | 16 +++++++++++++--- diff --git a/torrent.go b/torrent.go index 405748c90d55e2717991bace8f01b0b3efde640b..05598b3c151029e7075c0d0b5623f54f4521214a 100644 --- a/torrent.go +++ b/torrent.go @@ -12,6 +12,7 @@ "math/rand" "net/http" "net/url" "sort" + "strings" "sync" "text/tabwriter" "time" @@ -553,13 +554,17 @@ } } type pieceAvailabilityRun struct { - availability int64 count pieceIndex + availability int64 +} + +func (me pieceAvailabilityRun) String() string { + return fmt.Sprintf("%v(%v)", me.count, me.availability) } func (t *Torrent) pieceAvailabilityRuns() (ret []pieceAvailabilityRun) { rle := missinggo.NewRunLengthEncoder(func(el interface{}, count uint64) { - ret = append(ret, pieceAvailabilityRun{el.(int64), int(count)}) + ret = append(ret, pieceAvailabilityRun{availability: el.(int64), count: int(count)}) }) for _, p := range t.pieces { rle.Append(p.availability, 1) @@ -652,7 +657,12 @@ ) if t.info != nil { fmt.Fprintf(w, "Num Pieces: %d (%d completed)\n", t.numPieces(), t.numPiecesCompleted()) fmt.Fprintf(w, "Piece States: %s\n", t.pieceStateRuns()) - fmt.Fprintf(w, "Piece availability: %v\n", t.pieceAvailabilityRuns()) + fmt.Fprintf(w, "Piece availability: %v\n", strings.Join(func() (ret []string) { + for _, run := range t.pieceAvailabilityRuns() { + ret = append(ret, run.String()) + } + return + }(), " ")) } fmt.Fprintf(w, "Reader Pieces:") t.forReaderOffsetPieces(func(begin, end pieceIndex) (again bool) {