CSVReader

Inherits: RefCounted < Object

Streaming CSV reader with Variant conversion.

Description

CSVReader wraps DSVReader and converts each streamed field with CSVImporter.parse_record(). It can return each row as an Array or, when headers are enabled, as a Dictionary keyed by the first accepted row.

Properties

bool

cast_fields

true

bool

headers

false

Methods

void

close()

Error

get_error() const

PackedStringArray

get_header_names() const

int

get_length() const

int

get_line() const

int

get_position() const

bool

is_eof() const

Error

open(file_path: String, delimiter: String = ",", headers: bool = false, cast_fields: bool = true, options: Dictionary = {})

Error

open_with_dialect(file_path: String, dialect: CSVDialect)

Variant

read_row()

Array

read_rows(max_rows: int = 0)


Property Descriptions

bool cast_fields = true 🔗

  • void set_cast_fields(value: bool)

  • bool get_cast_fields()

If true, streamed fields are converted with CSVImporter.parse_record().


bool headers = false 🔗

  • void set_headers(value: bool)

  • bool get_headers()

If true, the first accepted row is used as dictionary keys for later rows.


Method Descriptions

void close() 🔗

Closes the current file and resets the reader.


Error get_error() const 🔗

Returns the last error from the underlying DSVReader.


PackedStringArray get_header_names() const 🔗

Returns the header names read from the first accepted row when headers is enabled.


int get_length() const 🔗

Returns the current file length in bytes, or 0 when no file is open.


int get_line() const 🔗

Returns the current one-based input line number.


int get_position() const 🔗

Returns the current file byte position, or 0 when no file is open.


bool is_eof() const 🔗

Returns true when the file has been fully read and no parsed rows remain.


Error open(file_path: String, delimiter: String = ",", headers: bool = false, cast_fields: bool = true, options: Dictionary = {}) 🔗

Opens file_path for streaming reads. If headers is true, the first accepted row is consumed as dictionary keys. If cast_fields is true, each field is converted to a Variant.


Error open_with_dialect(file_path: String, dialect: CSVDialect) 🔗

Opens file_path using dialect.


Variant read_row() 🔗

Reads one row. Returns an Array when headers is false, a Dictionary when headers is true, or null at EOF or after an error.


Array read_rows(max_rows: int = 0) 🔗

Reads up to max_rows rows. If max_rows is 0, reads until EOF.