read method

  1. @override
Future<Uint8List?> read()
override

Reads the next chunk, or null once the peer finished the stream.

Implementation

@override
Future<Uint8List?> read() async {
  final buffer = NativeBuffer(chunkSize);
  final event = await nativeRuntime.oneShot(
    'wt_recv_stream_read',
    (opId) => b.wt_recv_stream_read(_handle, buffer.data, chunkSize, opId),
  );
  if (event.isEof) {
    buffer.free();
    return null;
  }
  if (!event.isOk) {
    buffer.free();
    throw event.exception('read');
  }
  return adoptBuffer(buffer.handle, event.aux);
}