Skip to content

Instantly share code, notes, and snippets.

@angrycub
Created August 25, 2014 15:57
Show Gist options
  • Save angrycub/c84e4d6ee4128bf528db to your computer and use it in GitHub Desktop.
Save angrycub/c84e4d6ee4128bf528db 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