readBytes method Null safety

Uint8List readBytes(
  1. {int bytes = 0,
  2. int bits = 0}
)

Reads a byte array from the stream of length bytes and bits

Implementation

Uint8List readBytes({int bytes = 0, int bits = 0}) {
  var len = (bytes * 8) + bits;
  var totBytes = len ~/ 8;
  var remBits = len % 8;
  List<int> op = <int>[];
  if (remBits > 0) {
    op.add(read(bits: remBits));
  }
  for (int i = 0; i < totBytes; i++) {
    op.add(read(bytes: 1));
  }
  return Uint8List.fromList(op);
}