write method

  1. @override
Future<void> write(
  1. Uint8List bytes
)
override

Implementation

@override
Future<void> write(Uint8List bytes) async {
  final raw = _raw;
  if (raw == null) throw Exception();
  final buf = calloc<Uint8>(bytes.lengthInBytes);
  final u8Buf = buf.asTypedList(bytes.lengthInBytes);
  u8Buf.setRange(0, bytes.lengthInBytes, bytes);
  var offset = 0;
  while (isOpen && bytes.lengthInBytes - offset > 0) {
    final count = _api.write(
      raw,
      (buf + offset).cast(),
      bytes.lengthInBytes - offset,
    );
    if (count == -1) {
      break;
    } else {
      offset += count;
    }
  }
  calloc.free(buf);
}