Module streamcsv
High-level module for parsing CSV date
Functions
| header (record, header) | Adds headers to a record. |
| records (input[, options]) | Returns an iterator over records in a CSV file |
| file (input[, options]) | Reads a whole file into a table using streamcsv.records. |
Tables
| options | Options table to be passed to streamcsv.records and streamcsv.file |
Functions
- header (record, header)
-
Adds headers to a record.
Note that the resulting record saves a direct reference to the header as
passed into this function at index
[0], so modifying this value could cause trouble elsewhere.Parameters:
- record sequence Input record as a list of values
- header sequence as list of keys
Returns:
-
table
Record containing its values as integer (position) and string
(header) indices, and the header at the
[0]th index - records (input[, options])
-
Returns an iterator over records in a CSV file
Parameters:
- input A CSV-String or io-object to parse
- options options (optional)
- file (input[, options])
-
Reads a whole file into a table using streamcsv.records.
Note that a “file” in this context refers to a collection of CSV records, not an OS-level file.
Parameters:
- input A string containing CSV data or a readable I/O object
- options options (optional)
Tables
- options
-
Options table to be passed to streamcsv.records and streamcsv.file
Fields:
- rowsep string A single character representing the row separator.
- colsep string A single character representing the column separator.
- header A CSV string or Lua sequence containing the header values, or any other truthy value to read the first row of the input data.
- block integer The (max) block size in bytes to consume at a time. Defaults to 4MB.