readFixedLengthString method

String readFixedLengthString(
  1. int length
)

Implementation

String readFixedLengthString(int length)
{
    ByteData? data = read(length);

    if(data == null){
      throw 'no more data';
    }

    Uint8List byteList = Uint8List(length);

    for(int i = 0; i < length; i++) {
      byteList[i] = data.getUint8(i);
    }

    String out = String.fromCharCodes(byteList);

    // remove null characters
    out = String.fromCharCodes(out.codeUnits.where((code) => code != 0));

    return out;
}