readUtil function Null safety

Future<String> readUtil(
  1. RandomAccessFile file,
  2. {int charCode = 10}
)

Stream util for ...

Implementation

Future<String> readUtil(
  RandomAccessFile file, {
  int charCode: 10, // LF
}) async {
  var bytes = <int>[];
  while (true) {
    final int char = await file.readByte();
    if (char == -1) {
      throw StateError("eof");
    }

    if (char == charCode) break;

    bytes.add(char);
  }
  return String.fromCharCodes(bytes);
}