2
0
mirror of synced 2025-02-24 14:48:27 +00:00
torrent/metainfo/piece.go
Matt Joiner 5ac3e9ae54 Introduce metainfo.HashSize
This will be useful when BitTorrent 2 is implemented, and helps with creating arbitrary Info.Pieces
2017-12-29 12:17:58 +11:00

29 lines
502 B
Go

package metainfo
import "github.com/anacrolix/missinggo"
type Piece struct {
Info *Info
i int
}
func (p Piece) Length() int64 {
if p.i == p.Info.NumPieces()-1 {
return p.Info.TotalLength() - int64(p.i)*p.Info.PieceLength
}
return p.Info.PieceLength
}
func (p Piece) Offset() int64 {
return int64(p.i) * p.Info.PieceLength
}
func (p Piece) Hash() (ret Hash) {
missinggo.CopyExact(&ret, p.Info.Pieces[p.i*HashSize:(p.i+1)*HashSize])
return
}
func (p Piece) Index() int {
return p.i
}