bytesAvailable method

  1. @override
Future<int> bytesAvailable()
override

libusb bulk endpoints can't be peeked, so this does a short read and buffers whatever arrives. The base class's request/response loop only calls read while this returns > 0.

Implementation

@override
Future<int> bytesAvailable() async {
  if (_pending.isEmpty && isConnected) {
    final data = await _readBulk(_pollTimeoutMs);
    if (data != null) _pending.add(data);
  }
  return _pending.length;
}