Skip to content

Instantly share code, notes, and snippets.

@favila
Created July 13, 2016 21:04
Show Gist options
  • Save favila/fe499f64c60f2d9569f6c408bd9a3092 to your computer and use it in GitHub Desktop.
Save favila/fe499f64c60f2d9569f6c408bd9a3092 to your computer and use it in GitHub Desktop.
sha1 hash a stream in clojure
(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