-// Returns the state of pieces of the torrent. They are grouped into runs of
-// same state. The sum of the state run lengths is the number of pieces
-// in the torrent.
-func (t *Torrent) PieceStateRuns() []PieceStateRun {
- t.cl.mu.Lock()
- defer t.cl.mu.Unlock()
- return t.pieceStateRuns()
+type PieceStateRuns []PieceStateRun
+
+func (me PieceStateRuns) String() (s string) {
+ if len(me) > 0 {
+ var sb strings.Builder
+ sb.WriteString(me[0].String())
+ for i := 1; i < len(me); i += 1 {
+ sb.WriteByte(' ')
+ sb.WriteString(me[i].String())
+ }
+ return sb.String()
+ }
+ return
+}
+
+// Returns the state of pieces of the torrent. They are grouped into runs of same state. The sum of
+// the state run-lengths is the number of pieces in the torrent.
+func (t *Torrent) PieceStateRuns() (runs PieceStateRuns) {
+ t.cl.rLock()
+ runs = t.pieceStateRuns()
+ t.cl.rUnlock()
+ return