Hex.pm VersionHex DocsHex DownloadsErlang/OTP VersionsBuild Status

erl_csv is a pure Erlang library to encode and decode csv files.

Examples:

Encoding

DataSchema = [<<"city">>, <<"country">>, <<"continent">>],
DataRows = [
[<<"Madrid">>, <<"Spain">>, <<"Europe">>],
[<<"Krakow">>, <<"Poland">>, <<"Europe">>],
[<<"Berlin">>, <<"Germany">>, <<"Europe">>],
[<<"New York">>, <<"USA">>, <<"America">>],
[<<"Sidney">>, <<"Australia">>, <<"Asia">>]
],
Encoded = erl_csv:encode([DataSchema | DataRows]),

Then, in a single readable binary as iolist_to_binary(Encoded), we will see:

<<"city,country,continent\nMadrid,Spain,Europe\nKrakow,Poland,Europe\nBerlin,Germany,Europe\nNew York,USA,America\nSidney,Au"...>>

Decoding

If we are reading a file, we can decode as a stream as follows:

{ok, CsvStream} = erl_csv:decode_new_s(Filename),
{ok, do_import(CsvStream, WorkersQueue)};
do_import(stream_end, Decoded) ->
lists:reverse(Decoded);
do_import(Stream, Decoded) ->
{ok, MoreDecoded, MoreStream} = erl_csv:decode_s(Stream),
do_import(MoreStream, [MoreDecoded | Decoded]).

More details

See the documentation for more details.