readLine method

String? readLine({
  1. String? lineDelimiter,
})

Reads a single line from the file. lineDelimiter the end of line delimiter.

You can read the entire file by calling readLine repeatedly until it returns null.

The lineDelimiter may be one or two characters long. Defaults to the platform specific delimiter as defined by Platform().eol.

Implementation

String? readLine({String? lineDelimiter}) {
  lineDelimiter ??= Platform().eol;
  final line = StringBuffer();
  int byte;
  var priorChar = '';

  var foundDelimiter = false;

  while ((byte = _raf.readByteSync()) != -1) {
    final char = utf8.decode([byte]);

    if (_isLineDelimiter(priorChar, char, lineDelimiter)) {
      foundDelimiter = true;
      break;
    }

    line.write(char);
    priorChar = char;
  }
  final endOfFile = line.isEmpty && foundDelimiter == false;
  return endOfFile ? null : line.toString();
}