Object - io : ReadableCSVChannel

Represents a ReadableCSVChannel which could be used to read records from CSV file.

Constructor

Constructs a CSV channel from a CharacterChannel to read/write CSV records.



__init

(ReadableCharacterChannel byteChannel, Separator fs, int nHeaders)

  • fs Separator <(,| |:|string)> ,
  • Field separator, which will separate between the records in the CSV file

  • nHeaders int 0
  • Number of headers, which should be skipped prior to reading records

Methods

Indicates whether there's another record, which could be read.

Gets the next record from the CSV file.

Closes a given CSVChannel.

Returns a table, which corresponds to the CSV records.

hasNext

()

returns boolean

Indicates whether there's another record, which could be read.

 boolean hasNext = readableCSVChannel.hasNext();
  • Return Type

    (boolean)
  • True if there's a record

getNext

()

returns string[] | Error?

Gets the next record from the CSV file.

 string[]|io:Error? record = readableCSVChannel.getNext();
  • Return Type

    (string[] | Error?)
  • List of fields in the CSV or else an io:Error

close

()

returns Error?

Closes a given CSVChannel.

 io:Error? err = readableCSVChannel.close();
  • Return Type

    (Error?)
  • io:Error if any error occurred

getTable

(typedesc structType, string[] fieldNames)

returns table | Error

Returns a table, which corresponds to the CSV records.

 var tblResult1 = readableCSVChannel.getTable(Employee);
 var tblResult2 = readableCSVChannel.getTable(Employee, ["id", "name"]);

Parameters

  • structType typedesc
  • The object in which the CSV records should be deserialized

  • fieldNames string[] (default [])
  • The names of the fields used as the (composite)key of the table

  • Return Type

    (table | Error)
  • Table, which represents the CSV records or else an io:Error