readString method

String readString([
  1. int? len
])

Read a null-terminated string, or if len is provided, that number of bytes returned as a string.

Implementation

String readString([int? len]) {
  if (len == null) {
    final codes = <int>[];
    while (!isEOS) {
      final c = readByte();
      if (c == 0) {
        return String.fromCharCodes(codes);
      }
      codes.add(c);
    }
    throw ImageException('EOF reached without finding string terminator');
  }

  final s = readBytes(len);
  final bytes = s.toUint8List();
  final str = String.fromCharCodes(bytes);
  return str;
}