Last active
August 2, 2018 20:33
-
-
Save valericus/76bb94478cd0387757622f83b5e60b7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.security.MessageDigest | |
import akka.util.ByteString | |
import akka.stream.scaladsl.Sink | |
import scala.concurrent.ExecutionContext | |
trait SomeSink { | |
def digest: MessageDigest | |
def sink(implicit ec: ExecutionContext): Sink[ByteString, Future[String]] = | |
Sink.fold[MessageDigest, ByteString](digest) { (digest, chunk) => | |
digest.update(chunk.toArray) | |
digest | |
}.mapMaterializedValue(_.map(_.digest)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment