Reputation: 110
I am trying to learn Kotlin and am having trouble with file.foreachblock function(https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/java.io.-file/for-each-block.html).
Specifically I want to update the messageDigest with the byte array, but it is not clear to me how I would do this. Any examples would be great
something like
file.foreachblock(){ ->
messageDigest.update(it.bytearray, 0, it.length);
}
Upvotes: 2
Views: 617
Reputation: 23115
A lambda passed to forEachBlock
must accept two parameters. First is a ByteArray
buffer, and second is the number of bytes with actual data in that array.
file.forEachBlock { buffer, count ->
messageDigest.update(buffer, 0, count)
}
Upvotes: 6