Skip to content

Instantly share code, notes, and snippets.

@bitops
Forked from angrycub/convert_binary_ring
Created August 25, 2014 15:58
Show Gist options
  • Save bitops/ff05c2063a640b7ffe17 to your computer and use it in GitHub Desktop.
Save bitops/ff05c2063a640b7ffe17 to your computer and use it in GitHub Desktop.
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname convert_binary_ring -mnesia debug verbose
main([RingFile, OutFile]) ->
try
{ok, Binary} = file:read_file(RingFile),
Ring = binary_to_term(Binary),
try
file:write_file(OutFile, io_lib:format("~p.~n", [Ring])),
io:format("Saved ~p to ~p.~n", [RingFile, OutFile])
catch
A:B ->
io:format("Exception ~p:~p~n",[A,B])
end
catch
_:_ ->
usage()
end;
main([RingFile]) ->
main([RingFile, lists:append(RingFile,".txt")]);
main(_) ->
usage().
usage() ->
io:format("usage: convert_binary_ring RingFile [OutputFile]\n"),
halt(1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment