View Source erl_csv (erl_csv v0.3.2)
Summary
Functions
See also: decode/2.
Decode a stream of comma-separated lines into a stream of rows. The Decoder expects line by line input of valid csv lines with inlined escape sequences if you use it directly.
See also: encode/2.
Encode a table stream into a stream of RFC 4180 compliant CSV lines for writing to a file or other IO.
Types
-type decode_opts() ::
#{quotes => <<_:8>>, separator => <<_:8>>, delimiter => binary(), regex => term()}.
-type encode_opts() :: #{headers => boolean() | list(), separator => <<_:8>>, delimiter => binary()}.
Functions
-spec decode(iodata()) ->
{ok, iodata()} |
{has_trailer, iodata(), iodata()} |
{nomatch, iodata()} |
{error, term()}.
See also: decode/2.
-spec decode(iodata(), decode_opts()) -> {ok, iodata()} | {has_trailer, iodata(), iodata()} | {nomatch, iodata()} | {error, term()}.
Decode a stream of comma-separated lines into a stream of rows. The Decoder expects line by line input of valid csv lines with inlined escape sequences if you use it directly.
Options::separator
– The separator token to use, defaults to?,
. Must be a codepoint (syntax: ? + (your separator)).:headers
– When set totrue
, will take the first row of the csv and use it as header values. When set to a list, will use the given list as header values. When set tofalse
(default), will use no header values. When set to anything butfalse
, the resulting rows in the matrix will be maps instead of lists.
-spec decode_new_s(file:name_all()) -> {ok, erl_csv_decoder:csv_stream()} | {error, term()}.
-spec decode_new_s(file:name_all(), decode_opts()) -> {ok, erl_csv_decoder:csv_stream()} | {error, term()}.
-spec decode_s(erl_csv_decoder:csv_stream()) -> {ok, iolist(), erl_csv_decoder:csv_stream()} | {error, term()}.
-spec encode(iolist() | [map()]) -> iolist().
See also: encode/2.
-spec encode(iolist() | [map()], encode_opts()) -> iolist().
Encode a table stream into a stream of RFC 4180 compliant CSV lines for writing to a file or other IO.
Options::separator
– The separator token to use, defaults to?,
. Must be a codepoint (syntax: ? + your separator token).:delimiter
– The delimiter token to use, defaults to\"\\r\\n\"
.:headers
– When set totrue
, uses the keys of the first map as the first element in the stream. All subsequent elements are the values of the maps. When set to a list, will use the given list as the first element in the stream and order all subsequent elements using that list. When set tofalse
(default), will use the raw inputs as elements. When set to anything butfalse
, all elements in the input stream are assumed to be maps.