CSV encoding and decoding for Dart, with streams, auto-detection and Excel compatibility
open sourceMITfree
csv is a CSV library for Dart, inspired by PapaParse. Its decoder and encoder are stream transformers that emit one row per event, it detects delimiters and line endings automatically, handles quoted fields, escaped quotes and malformed input, and can parse numbers and booleans. It has built-in Excel-compatible output (UTF-8 BOM, semicolon separator, CRLF line endings) and supports multi-character field delimiters.
Problems it solves
- read and write CSV files in a Flutter app
- export data from Dart to a CSV that opens correctly in Excel
- parse a large CSV file row by row as a stream in Dart
Features
- Decoder and encoder as stream transformers, one row per event
- Automatic detection of delimiters and line endings
- Handles quoted fields, escaped quotes and malformed CSV
- Excel-compatible output with UTF-8 BOM, semicolons and CRLF
- Optional parsing of numbers and booleans
- Multi-character field delimiters
Limitations
- Its default CRLF line delimiter can turn into doubled carriage returns when written to a file on Windows with some APIs; use \n or a binary writer.1
