4 g "github.com/anacrolix/generics"
8 Info *Info // Can we embed the fields here instead, or is it something to do with saving memory?
14 func (p Piece) Length() int64 {
17 pieceLength := p.Info.PieceLength
18 lastFileEnd := int64(0)
20 p.Info.FileTree.upvertedFiles(pieceLength, func(fi FileInfo) {
24 fileStartPiece := int(offset / pieceLength)
25 if fileStartPiece > p.i {
29 lastFileEnd = offset + fi.Length
30 offset = (lastFileEnd + pieceLength - 1) / pieceLength * pieceLength
32 ret := min(lastFileEnd-int64(p.i)*pieceLength, pieceLength)
38 if p.i == p.Info.NumPieces()-1 {
39 return p.Info.TotalLength() - int64(p.i)*p.Info.PieceLength
41 return p.Info.PieceLength
44 func (p Piece) Offset() int64 {
45 return int64(p.i) * p.Info.PieceLength
48 func (p Piece) V1Hash() (ret g.Option[Hash]) {
52 copy(ret.Value[:], p.Info.Pieces[p.i*HashSize:(p.i+1)*HashSize])
57 func (p Piece) Index() int {