FedP2P/metainfo/pieces.go

23 lines
327 B
Go
Raw Normal View History

2020-05-13 12:32:20 +08:00
package metainfo
import (
"crypto/sha1"
"io"
)
func GeneratePieces(r io.Reader, pieceLength int64, b []byte) ([]byte, error) {
for {
h := sha1.New()
written, err := io.CopyN(h, r, pieceLength)
if written > 0 {
b = h.Sum(b)
}
if err == io.EOF {
return b, nil
}
if err != nil {
return b, err
}
}
}