Erlang Thursday – erl_tar:table/1

Today’s Erlang Thursday is on erl_tar:table/1.

erl_tar:table/1 returns a list of filenames included in the tar file.

% {ok,["dog.txt","cat.txt","pony.txt","bear.txt"]}

There is also a version erl_tar:table/2 that takes a options list as well.

erl_tar:table("animal_sounds.tar.gz", [compressed]).
% {ok,["dog.txt","cat.txt","pony.txt","bear.txt"]}
erl_tar:table("animal_sounds.tar.gz", [compressed,verbose]).
% {ok,[{"dog.txt",regular,5,
%       {{2015,9,23},{22,18,47}},
%       420,501,20},
%      {"cat.txt",regular,5,{{2015,9,23},{22,18,56}},420,501,20},
%      {"pony.txt",regular,8,{{2015,9,23},{22,19,10}},420,501,20},
%      {"bear.txt",regular,19,
%       {{2015,9,23},{22,21,16}},
%       420,501,20}]}

With the verbose option, instead of just getting a list of filenames, we get a list of tuples when we pass verbose.

The tuple is: Filename, Filetype (regular file/directory or a symbolic link), Bytes of the file, Timestamp tuple, Permissions (expressed in decimal instead of octal), UserId, and GroupId.

The documentation does not specify any of the information about the return type, and the credit for clarification of what the 420,501,20 items represent is all from Robert Virding, from emailing him this post to be translated as part of LFE Fridays.