Bula
Bula

Reputation: 2792

Computing the checksum of a file in erlang

I am trying to compute the md5 checksum of a large file by using the BIFs that erlang offers:

  1. erlang:md5_init()
  2. erlang:md5_update()
  3. erlang:md5_final()

In the following code:

to_md5_large(File) ->
    case file:read_file(File) of
        {ok, <<A:4/binary,B/binary>>} -> md5_helper(B,erlang:md5_init(A));
        {error,Reason} -> exit(Reason)
    end.

md5_helper(<<A:4/binary,B>>,Acc) -> md5_helper(B,erlang:md5_update(Acc,A));
md5_helper(A,Acc) -> 
    B =     erlang:md5_update(Acc,A),
    erlang:md5_final(B).

However it seems as if the md5_init() doesn't get recognised. When I compile everything works fine returning the {ok,module} however when I run I get an error saying that there is an undefined function md5_init on the line shown above. Any suggestions?

Upvotes: 0

Views: 585

Answers (1)

Pascal
Pascal

Reputation: 14042

erlang:md5_init has no parameter.

Don't forget that no check is done at compilation about functions defined in other modules.

Upvotes: 3

Related Questions