package meta import ( "crypto/sha1" "dim13.org/btget/bencode" ) type Piece [sha1.Size]byte func (p Piece) Check(b []byte) bool { return sha1.Sum(b) == p } type Pieces []Piece func (p *Pieces) UnmarshalBencode(b []byte) (int, error) { var tmp []byte n, err := bencode.Unmarshal(b, &tmp) if err != nil { return 0, err } count := len(tmp) / sha1.Size *p = make(Pieces, count) for i := 0; i < count; i++ { off := i * sha1.Size copy((*p)[i][:], tmp[off:off+sha1.Size]) } return n, nil }