- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
:-6ren">
我需要在 Elixir 中计算文件的 md5 总和,如何实现?
我希望是这样的:
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
iex(22)> Mix.Utils.read_path("file", [:sha512])
{:ok, "Elixir"} #the expected was {:checksum, "<checksum_value>"}
最佳答案
万一其他人发现这个问题并错过了@FredtheMagicWonderDog 的评论。 . .
查看此博文:http://www.cursingthedarkness.com/2015/04/how-to-get-hash-of-file-in-exilir.html
这是相关的代码:
File.stream!("./known_hosts.txt",[],2048)
|> Enum.reduce(:crypto.hash_init(:sha256),fn(line, acc) -> :crypto.hash_update(acc,line) end )
|> :crypto.hash_final
|> Base.encode16
#=> "97368E46417DF00CB833C73457D2BE0509C9A404B255D4C70BBDC792D248B4A2"
关于functional-programming - 如何在 Elixir 中计算文件校验和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41008487/
如何在 PHP 中生成 CRC-8 校验和? 最佳答案 function crcnifull ($dato, $byte) { static $PolyFull=0x8c; for ($i=0
我正在编写代码来使用 32 位无符号整数计算 CRC16。当尝试打印执行 CRC 操作的 XOR 函数的返回值时,它总是打印 0。我尝试了各种调试方法,例如打印语句,但是,我似乎无法弄清楚! 这是我的
ThinkPHP3.2.3验证码显示、刷新、校验 ,具体如下: 显示验证码 首先在Home/Controller下创建一个公共控制器PublicController
我想将自定义验证绑定(bind)到 TimePicker 自定义控件,但下面的代码显示“无法将内容添加到 TimePicker 的对象类型。”。
目录 Spring 校验(validator,JSR-303)实现 什么是JSR-303规范 与Spring MVC结合 实体类添加
导包和配置 导入 JSR 303 的包、hibernate valid 的包 ?
我是一名优秀的程序员,十分优秀!