I think we could go for something more general instead. Right now it's very 
easy to define stream "sources" with various functions such as Stream.transform 
or Stream.resource. It's not as easy to create a "sink" stream that would 
accept the input lazily. This could easily allow solving the issue at hand in a 
fairly clean manner, for example:

sink =
  Stream.consume(
    fn -> :crypto.hash_init(:md5) end,
    fn acc, data -> :crypto.hash_update(acc, data) end,
    fn acc -> :crypto.hash_final(acc) end)

Enum.into(File.stream!(path), sink)

I think there will be many instances where the collectable implementation could 
be expressed in terms of this operation without requiring the full-blown struct 
and protocol implementation.

Michał.

On 13 Jun 2017, 16:23 +0200, Amos King <[email protected]>, wrote:
> I think that those algorithms are useful for more than files and already 
> exist in Erlang. What advantage do you see over using
>
> File.open(path) |> :crypto.hash(:md5)
>
> That isn't streaming but I think it is very clear.
>
> Amos King
> Binary Noggin
>
> On Jun 13, 2017, at 08:43, [email protected] wrote:
>
> > Hello everybody,
> >
> > I propose adding a File.checksum/2 function to create a 
> > (md5/sha1/sha256/...) checksum of a given file path.
> > The function might have the following signature:
> >
> > checksum(String.t, Atom.t) :: {:ok, String.t} | {:error, String.t}
> >
> > - The first attribute is the path to the file where a checksum should be 
> > computed.
> > - The second attribute addresses the used hashing algorithm as an atom e.g. 
> > :md5, :sha, :sha256, according to the the algorithms provided by erlang.
> >
> > After searching the web for quite a long time, it was hard to find a 
> > suitable AND efficient implementation of creating file checksums with 
> > Elixir.
> > Therefore, I’m convinced this function will help many developers creating 
> > file checksums.
> >
> > Regards,
> > Matthias
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "elixir-lang-core" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to [email protected].
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/elixir-lang-core/ee960cf6-b4dd-4638-acc4-a3eee37c63aa%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
> --
> You received this message because you are subscribed to the Google Groups 
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elixir-lang-core/9F42D635-2B27-4F1B-B972-DFDD7625F523%40binarynoggin.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/f5adb87b-3227-4899-b282-5afd936e83f0%40Spark.
For more options, visit https://groups.google.com/d/optout.

Reply via email to