2016-04-04 03:48:39 +00:00
|
|
|
package metainfo
|
|
|
|
|
|
|
|
import "github.com/anacrolix/missinggo"
|
|
|
|
|
|
|
|
type Piece struct {
|
|
|
|
Info *InfoEx
|
|
|
|
i int
|
|
|
|
}
|
|
|
|
|
2016-04-19 04:11:11 +00:00
|
|
|
func (p Piece) Length() int64 {
|
|
|
|
if p.i == p.Info.NumPieces()-1 {
|
|
|
|
return p.Info.TotalLength() - int64(p.i)*p.Info.PieceLength
|
2016-04-04 03:48:39 +00:00
|
|
|
}
|
2016-04-19 04:11:11 +00:00
|
|
|
return p.Info.PieceLength
|
2016-04-04 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2016-04-19 04:11:11 +00:00
|
|
|
func (p Piece) Offset() int64 {
|
|
|
|
return int64(p.i) * p.Info.PieceLength
|
2016-04-04 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2016-04-19 04:11:11 +00:00
|
|
|
func (p Piece) Hash() (ret Hash) {
|
|
|
|
missinggo.CopyExact(&ret, p.Info.Pieces[p.i*20:(p.i+1)*20])
|
2016-04-04 03:48:39 +00:00
|
|
|
return
|
|
|
|
}
|