FileDataSource.prototype.run = function()

in loader/lib/DataSource.js [292:335]


FileDataSource.prototype.run = function() {
  udebug.log("run");
  var desc, extraLines, fields, row, record;
  desc = this.bufferDesc;
  extraLines = 0;

  while(this.running && ! desc.atEnd) {
    extraLines = this.lineScanner.scan(desc);  // Scan the line
    this.physLineNo += (extraLines + 1);
    if(this.options.columnsInHeader) {
      udebug.log("Setting columns from header");
      if(desc.lineHasFields) {
        this.options.columnsInHeader = null;  // reset from true to null
        fields = this.fieldScanner.scan(desc);  // Extract the data fields
        this.columns.setColumnsFromArray(fields);  // Creates a new tableHandler on next write
      }
    } else if (this.skipping) {
      theController.dsDiscardedItem();
    } else {
      theController.plugin.onScanLine(this.physLineNo, desc.source,
                                      desc.lineStart, desc.lineEnd);
      if(desc.lineHasFields) {
        fields = this.fieldScanner.scan(desc);    // Extract the data fields
        record = new this.Record(desc, row);
        theController.dsNewItem(record);
      }
    }
    desc.lineStart = desc.lineEnd + 1;   // Advance to first char. of next line
  }

  if(this.shutdown) {
    /* Controller has shut us down, e.g. because of DO N ROWS */
    theController.dsFinished();
  } else if(this.fd === null) {
    /* We have been reading data from a string passed on the command line */
    theController.dsFinished();
  } else if(desc.atEnd) {
    /* Read to the end of a read buffer; read again. */
    this.read();
  } else {
    /* Reaching this point is probably a bug */
    console.log("why are we here?", this);
  }
};