Created
July 13, 2016 21:04
-
-
Save favila/fe499f64c60f2d9569f6c408bd9a3092 to your computer and use it in GitHub Desktop.
sha1 hash a stream in clojure
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
(defn sha1-hash-stream [^InputStream stream] | |
(let [buffer (byte-array 8192) | |
md (MessageDigest/getInstance "SHA-1")] | |
(loop [] | |
(let [taken (.read stream buffer 0 8192)] | |
(if (> taken 0) | |
(do (.update md buffer 0 taken) | |
(recur)) | |
(.digest md)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment