Created
January 29, 2016 19:19
-
-
Save asonge/e3e1c58d517e2da78601 to your computer and use it in GitHub Desktop.
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
# In case anyone is wondering how to easily use the :crypto hash or hmac API's from elixir-land, here you go. | |
File.stream!(filename, [:read, {:read_ahead, 65535}], 65535) | |
|> Enum.reduce(:crypto.hash_init(:sha), &:crypto.hash_update(&2, &1)) | |
|> :crypto.hash_final | |
|> Base.encode16 | |
# Line 3 opens up a stream, and we're reading in 64KB chunks from the FS which is roughly pretty efficient | |
# In line 4, we initialize our hash (which returns a context) and put that as the default value in the reducer | |
# The hash_update in the reducer returns the modified context. Remember arg1 is the item, and arg2 is the accumulator | |
# Line 5 we finalize | |
# Line 6 we turn it into hex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment