writeViewToStream method

  1. @override
Stream<List<int>> writeViewToStream(
  1. GpsPointsView<GpsPoint> view
)
override

Converts view to a Stream of bytes. Override in children.

Implementation

@override
Stream<List<int>> writeViewToStream(GpsPointsView view) async* {
  final gpc = view as GpcEfficient;

  // Split it in chunks, making sure in case of huge element size that we
  // write at least one element per chunk.
  final elementsPerChunk = max<int>(1, chunkSize ~/ gpc.elementSizeInBytes);

  var elementsWritten = 0;
  while (elementsWritten < gpc.length) {
    // Don't try to write more elements than there are yet unwritten.
    final elementsToWrite =
        min<int>(elementsPerChunk, gpc.length - elementsWritten);

    yield gpc.exportAsBytes(elementsWritten, elementsToWrite);

    elementsWritten += elementsToWrite;
  }
}