scalaz/scalaz-stream — pull request #200 by sidneyshek (2014-07-09 00:08:28+00:00)
Title: 'scalaz.stream.hash'es don't hash the entire stream

Piping a stream with more than one Emit state (e.g. generated by io.chunkR) through the hashers doesn't appear to hash the entire stream; instead it appears to emit the hash for only the bytes in the current Emit state. Perhaps that was the intent, but it doesn't seem too useful to me.

It appears the problem is due to the digest.digest() call in emitLazy being called for each emission. Calling digest() resets the state of the MessageDigest.

One 'solution' would be to clone the digest before calling digest(), but that only works if the MessageDigest implementation implements Cloneable. Another possibility may be for the hash transducers to return the MessageDigest itself, and let the stream consumer call digest (but that's also ugly too).