multiformats / go-multihash

Multihash implementation in Go
MIT License
234 stars 56 forks source link

Add func SumStreamN for hashing first n bytes only #139

Closed shoce closed 3 years ago

shoce commented 3 years ago

func SumStreamN(r io.Reader, n int64, code uint64, length int) (Multihash, error) that uses io.CopyN instead of io.Copy

shoce commented 3 years ago

I need this for a tool i am developing right now. The tool syncs a big file between two machines. If the downloading side has the file with the same name and size smaller than the file on the other side, then the tool checks if hashes are the same. So for this i need to check hash of the first n bytes of the file.

Stebalien commented 3 years ago

Please wrap your io.Reader in an io.LimitedReader. There's no need to add a new function.

shoce commented 3 years ago

Please wrap your io.Reader in an io.LimitedReader. There's no need to add a new function.

Wow thanks, i did not know about io.LimitedReader existence.