Csv
Config & IO
Fast CSV parsing for the BEAM (NimbleCSV-shaped).
Hot path is Erlang binary matching. Parsed fields may be binary references into the current row buffer — copy with care if you retain fields across rows or send them to another process.
Prefer large byte chunks from the source (Server.bodyStream 65536, Multipart.fileStream, or File.streamBytes).
Server.bodyStream 65536 req
|> Csv.decode Csv.rfc4180
|> Stream.stoppableFoldl validate 0Consume HTTP body streams inside handle with tryFoldl / stoppableFoldl, not attemptFoldl.
Types
Options
type Options = OptionsParser options (separator, escape, header skipping).
Examples
Csv.rfc4180Row
type alias Row =
List StringOne CSV record as field strings.
Examples
[ "Ada", "Lovelace" ]Error
type Error
= ParseFailed Int String
| InvalidRow Int StringParse or validation failure with a 1-based row number.
Examples
Csv.invalidRow 2 "bad email"Values
rfc4180
rfc4180 : OptionsRFC 4180 defaults: comma separator, double-quote escape, skip header row.
Examples
Csv.rfc4180tsv
tsv : OptionsTab-separated values with the same escape / header defaults as rfc4180.
Examples
Csv.tsvwithSkipHeaders
withSkipHeaders : Bool -> Options -> OptionsSet whether the first row is treated as headers and dropped.
Examples
Csv.withSkipHeaders False Csv.rfc4180errorToString
errorToString : Error -> StringHuman-readable Error.
Examples
Csv.errorToString errinvalidRow
invalidRow : Int -> String -> ErrorBuild an InvalidRow for application validation failures.
Examples
Csv.invalidRow 2 "bad email"decode
decode : Options -> Stream Bytes -> Stream (Result Error Row)Lazily decode CSV records from byte chunks (quoted multiline fields OK).
Examples
Csv.decode Csv.rfc4180 (Server.bodyStream 65536 req)decodeLines
decodeLines : Options -> Stream String -> Stream (Result Error Row)Lazily decode from a line-oriented stream (NimbleCSV parse_stream shape). Lines that open a quote continue until the escape closes.
Examples
Csv.decodeLines Csv.rfc4180 (File.stream path)decodeString
decodeString : Options -> String -> Result Error (List Row)Eagerly decode a whole CSV document.
Examples
Csv.decodeString Csv.rfc4180 "a,b\n1,2\n"