Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/nimble_csv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,17 @@ defmodule NimbleCSV do

@doc """
Eagerly dumps an enumerable into iodata (a list of binaries and bytes and other lists).

Each value is converted to a string using `String.Chars.to_string/1`.
"""
@callback dump_to_iodata(rows :: Enumerable.t()) :: iodata()

@doc """
Lazily dumps from an enumerable to a stream.

It returns a stream that emits each row as iodata.

Each value is converted to a string using `String.Chars.to_string/1`.
"""
@callback dump_to_stream(rows :: Enumerable.t()) :: Enumerable.t()

Expand Down Expand Up @@ -690,7 +694,7 @@ defmodule NimbleCSV do
end

defp maybe_escape(entry, check) do
entry = to_string(entry)
entry = String.Chars.to_string(entry)

case :binary.match(entry, check) do
{_, _} ->
Expand Down
6 changes: 3 additions & 3 deletions test/nimble_csv_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ defmodule NimbleCSVTest do
"""

assert IO.iodata_to_binary(
Enum.to_list(CSV.dump_to_stream([["name", "age"], ["john\ndoe", 27]]))
Enum.to_list(CSV.dump_to_stream([["name", "dob"], ["john\ndoe", ~D[1970-01-01]]]))
) == """
name,age\r\n\
name,dob\r\n\
"john
doe",27\r\n\
doe",1970-01-01\r\n\
"""

assert IO.iodata_to_binary(
Expand Down
Loading