我需要计算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 –