All Projects → beatrichartz → Csv

beatrichartz / Csv

Licence: mit
CSV Decoding and Encoding for Elixir

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Csv

Vxg.media.sdk.android
Market leading Android SDK with encoding, streaming & playback functionality
Stars: ✭ 119 (-70.1%)
Mutual labels:  stream, encoding
eec
A fast and lower memory excel write/read tool.一个非POI底层,支持流式处理的高效且超低内存的Excel读写工具
Stars: ✭ 93 (-76.63%)
Mutual labels:  csv, stream
Csvbuilder
Easily encode complex JSON objects to CSV with CsvBuilder's schema-like API
Stars: ✭ 128 (-67.84%)
Mutual labels:  stream, csv
Csv Stream
📃 Streaming CSV Parser for Node. Small and made entirely out of streams.
Stars: ✭ 98 (-75.38%)
Mutual labels:  stream, csv
scala-csv-parser
CSV parser library.
Stars: ✭ 24 (-93.97%)
Mutual labels:  csv, parsing
React Papaparse
react-papaparse is the fastest in-browser CSV (or delimited text) parser for React. It is full of useful features such as CSVReader, CSVDownloader, readString, jsonToCSV, readRemoteFile, ... etc.
Stars: ✭ 116 (-70.85%)
Mutual labels:  stream, csv
BencodeNET
.NET library for encoding/decoding bencode and reading/writing torrent files
Stars: ✭ 133 (-66.58%)
Mutual labels:  encoding, parsing
Yacr
Yet another CSV Reader
Stars: ✭ 62 (-84.42%)
Mutual labels:  csv, encoding
pcap-processor
Read and process pcap files using this nifty tool
Stars: ✭ 36 (-90.95%)
Mutual labels:  csv, stream
parallel stream
A parallelized stream implementation for Elixir
Stars: ✭ 86 (-78.39%)
Mutual labels:  stream, parallelism
Iostreams
IOStreams is an incredibly powerful streaming library that makes changes to file formats, compression, encryption, or storage mechanism transparent to the application.
Stars: ✭ 84 (-78.89%)
Mutual labels:  stream, csv
Rtspallthethings
Deprecated RTSP media server -- Use github.com/aler9/rtsp-simple-server instead.
Stars: ✭ 258 (-35.18%)
Mutual labels:  stream, encoding
Fast Csv
CSV parser and formatter for node
Stars: ✭ 1,054 (+164.82%)
Mutual labels:  stream, csv
Corrode
A batteries-included library for reading binary data.
Stars: ✭ 116 (-70.85%)
Mutual labels:  stream, parsing
Semantic Csv
Higher level tools for working with CSV data and files
Stars: ✭ 232 (-41.71%)
Mutual labels:  csv, parsing
Hashlib4pascal
Hashing for Modern Object Pascal
Stars: ✭ 132 (-66.83%)
Mutual labels:  stream, encoding
Rust Lexical
Lexical, to- and from-string conversion routines.
Stars: ✭ 192 (-51.76%)
Mutual labels:  encoding, parsing
Readr
Read flat files (csv, tsv, fwf) into R
Stars: ✭ 821 (+106.28%)
Mutual labels:  csv, parsing
tabular-stream
Detects tabular data (spreadsheets, dsv or json, 20+ different formats) and emits normalized objects.
Stars: ✭ 34 (-91.46%)
Mutual labels:  csv, stream
text2json
Performant parser for textual data (CSV parser)
Stars: ✭ 33 (-91.71%)
Mutual labels:  csv, stream

CSV Build Status Coverage Status Inline docs Hex pm Downloads

RFC 4180 compliant CSV parsing and encoding for Elixir. Allows to specify other separators, so it could also be named: TSV. Why it is not idk, because of defaults I think.

Why do we want it?

It parses files which contain rows (in utf-8) separated by either commas or other separators.

If that's not enough reason to absolutely ❤️ 💚 💕 ❤️ 💞 💖 it, it also parses a CSV file in order about 2x times as fast as an unparallelized stream implementation 🚀

When do we want it?

Now.

How do I get it?

Add

{:csv, "~> 2.4"}

to your deps in mix.exs like so:

defp deps do
  [
    {:csv, "~> 2.4"}
  ]
end

Note: Elixir 1.1.0 is required for all versions above 1.1.5.

From 1.x to 2.x - the tasty ™️ update.

2.x has some nice new features like the separation between hair- and error-raising decode! and the zen of decode, better error messages and an easier to understand codebase for you to contribute.

The only thing you have to do to upgrade to 2.x is to change your calls to decode to decode!, and adjust your exceptions-catching code to catch the right exceptions still. But why not take full advantage and convert to decode and the new tuple stream?

You know you want it.

Great! How do I use it right now?

There are two interesting things you want to do regarding csvs - encoding end decoding.

Decoding

Do this to decode:

File.stream!("data.csv") |> CSV.decode

And you'll get a stream of row tuples:

[ok: ["a", "b"], ok: ["c", "d"]]

And, potentially error tuples:

[error: "Row has length 3 - expected length 2 on line 1", ok: ["c", "d"]]

Use the bang to decode! into a two-dimensional list, raising errors as they occur:

File.stream!("data.csv") |> CSV.decode!

Be sure to read more about decode and its angry sibling decode!

Encoding

Do this to encode a table (two-dimensional list):

table_data |> CSV.encode

And you'll get a stream of lines ready to be written to an IO. So, this is writing to a file:

file = File.open!("test.csv", [:write, :utf8])
table_data |> CSV.encode |> Enum.each(&IO.write(file, &1))

I have this file, but it's tab-separated ⁉️

Pass in another separator to the decoder:

File.stream!("data.csv") |> CSV.decode(separator: ?\t)

If you want to take revenge on whoever did this to you, encode with semicolons like this:

your_data |> CSV.encode(separator: ?;)

You can also specify headers when encoding, which will encode map values into the right place:

[%{"a" => "value!"}] |> CSV.encode(headers: ["z", "a"])
# ["z,a\\r\\n", ",value!\\r\\n"]

You'll surely appreciate some more info on encode

Polymorphic encoding

Make sure your data gets encoded the way you want - implement the CSV.Encode protocol for whatever strange you wish to encode:

defimpl CSV.Encode, for: MyData do
  def encode(%MyData{has: fun}, env \\ []) do
    "so much #{fun}" |> CSV.Encode.encode(env)
  end
end

Or similar.

Ensure performant encoding

The encoding protocol implements a fallback to Any for types where a simple call o to_string will provide unambiguous results. Protocol dispatch for the fallback to Any is very slow when protocols are not consolidated, so make sure you have consolidate_protocols: true in your mix.exs or you consolidate protocols manually for production in order to get good performance.

There is more to know about everything ™️ - Check the doc

License

MIT

Contributions & Bugfixes are most welcome!

Please make sure to add tests. I will not look at PRs that are either failing or lowering coverage. Also, solve one problem at a time.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].