### Write CSV Data to IO Source: https://github.com/jimm/csvlixir/blob/main/README.md Use `CSVLixir.write` to generate CSV strings and `IO.write` to output them. This example demonstrates writing multiple rows, including one with escaped quotes, to standard output. ```elixir CSVLixir.write([["abc", "def", "gh",""i"], [123, 456, 789]]) |> Enum.each(&IO.write/1) #=> abc,def,"gh"",""i" #=> 123,456,789 #=> :ok ``` -------------------------------- ### Write CSV Rows to a File Line by Line Source: https://github.com/jimm/csvlixir/blob/main/README.md Open a file in write mode (optionally with `:utf8` encoding), and use `IO.write` with `CSVLixir.write_row` to write individual rows to the file. ```elixir f = File.open!("/tmp/csvlixir.csv", [:write, :utf8]) IO.write(f, CSVLixir.write_row(["garçon", "waiter"])) IO.write(f, CSVLixir.write_row(["résumé", "resume"])) File.close(f) File.read!("/tmp/csvlixir.csv") # => "garçon,waiter\nrésumé,resume\n" ``` -------------------------------- ### Write CSV Data to a File Using Streams Source: https://github.com/jimm/csvlixir/blob/main/README.md Open a file in write mode, pipe a stream of CSV data generated by `CSVLixir.write` into `IO.write` for each file chunk, and ensure the stream is fully processed with `Stream.run`. ```elixir f = File.open!("/tmp/csvlixir.csv", [:write]) 1..3 |> Stream.map(&([&1, &1+1 ,&1+2])) |> CSVLixir.write |> Stream.each(&(IO.write(f, &1))) |> Stream.run File.close(f) File.read!("/tmp/csvlixir.csv") # => "1,2,3\n2,3,4\n3,4,5\n" ``` -------------------------------- ### Add CSVLixir to Mix Dependencies Source: https://github.com/jimm/csvlixir/blob/main/README.md Add CSVLixir to your project's dependencies in `mix.exs`. ```elixir def deps do [{:csvlixir, "~> 2.0.3"}] end ``` -------------------------------- ### Write CSV Data to a Stream Source: https://github.com/jimm/csvlixir/blob/main/README.md Use `CSVLixir.write` to transform a list of lists into a stream of CSV strings. Each string in the stream ends with a newline character. Convert the stream to a list to see all output strings. ```elixir CSVLixir.write([["first", "row"], [123, 456]]) |> Enum.to_list #=> ["first,row\n", "123,456\n"] ``` -------------------------------- ### Read CSV Data from a File Source: https://github.com/jimm/csvlixir/blob/main/README.md Use `CSVLixir.read` to read CSV data from a file path. It returns a Stream that generates rows of CSV data. Convert the stream to a list for immediate processing. ```elixir CSVLixir.read("path/to/my.csv") |> Enum.to_list #=> [["row", "one"], ["row", "two"]] ``` -------------------------------- ### Write a Single CSV Row to a String Source: https://github.com/jimm/csvlixir/blob/main/README.md Use `CSVLixir.write_row` to convert a single list into a CSV formatted string, ending with a newline. ```elixir CSVLixir.write_row(["a", "b", "c"]) #=> "a,b,c\n" ``` -------------------------------- ### Parse CSV Data from a String Source: https://github.com/jimm/csvlixir/blob/main/README.md Use `CSVLixir.parse` to parse CSV data directly from a string. This function returns a list of lists representing the CSV rows. ```elixir CSVLixir.parse("abc,def,ghi\n123,456,789") #=> [["abc","def","ghi"],["123","456","789"]] CSVLixir.parse(~s{abc,def,"gh"",""i}) #=> [["abc", "def", "gh",""i]] CSVLixir.parse(File.read!("/tmp/foo.csv")) #=> [["row", "one"], ["row", "two"]] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.