Created
December 2, 2016 22:12
-
-
Save acj/affcc31213e8caf858828f6d7f56fc6e to your computer and use it in GitHub Desktop.
Compute MD5 digest in Elixir using streams and chunks
This file contains 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
def md5_digest_for_file_at_path(file_path) do | |
File.stream!(file_path, [:read, :binary], 1024 * 1024) | |
|> Stream.chunk(1) | |
|> Enum.reduce( | |
:crypto.hash_init(:md5), | |
fn(chunk, acc) -> | |
:crypto.hash_update(acc, hd(chunk)) | |
end) | |
|> :crypto.hash_final | |
|> Base.encode16 | |
|> String.downcase | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment