readString method Null safety

  1. @override
String readString(
  1. {int? size,
  2. bool utf8 = true}
)
override

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

Implementation

@override
String readString({int? size, bool utf8 = true}) {
  if (size == null) {
    final codes = <int>[];
    while (!isEOS) {
      var c = readByte();
      if (c == 0) {
        return utf8
            ? Utf8Decoder().convert(codes)
            : String.fromCharCodes(codes);
      }
      codes.add(c);
    }
    throw ArchiveException('EOF reached without finding string terminator');
  }

  final s = readBytes(size);
  final bytes = s.toUint8List();
  final str =
      utf8 ? Utf8Decoder().convert(bytes) : String.fromCharCodes(bytes);
  return str;
}