我需要計算Elixir中一個文件的md5總和,這怎麼能實現呢? 我期望是這樣的:如何計算Elixir中的文件校驗和?
iex(15)> {:ok, f} = File.open "file"
{:ok, #PID<0.334.0>}
iex(16)> :crypto.hash(:md5, f)
** (ArgumentError) argument error
:erlang.iolist_to_binary(#PID<0.334.0>)
(crypto) crypto.erl:225: :crypto.hash/2
但顯然它不工作..
Mix.Utils的文檔講述read_path功能link,但它並沒有任何工作。
iex(22)> Mix.Utils.read_path("file", [:sha512])
{:ok, "Elixir"} #the expected was {:checksum, "<checksum_value>"}
是否有任何庫以簡單的方式提供此類功能?
相關博文:http://www.cursingthedarkness.com/2015/04/how-to-get-hash-of-file-in-exilir.html –