writeBytes method

Future<void> writeBytes(
  1. Uint8List data, {
  2. int offset = 0,
})

Writes data to the file starting at offset.

Implementation

Future<void> writeBytes(Uint8List data, {int offset = 0}) async {
  const maxChunkSize = 16 * 1024;
  var bytesSent = 0;
  final futures = <Future<void>>[];
  while (bytesSent < data.length) {
    final chunkSize = min(data.length - bytesSent, maxChunkSize);
    final chunkBegin = bytesSent;
    final chunkEnd = chunkBegin + chunkSize;
    final chunk = Uint8List.sublistView(data, chunkBegin, chunkEnd);
    futures.add(_writeChunk(chunk, offset: offset + bytesSent));
    bytesSent += chunkSize;
  }
  await Future.wait(futures);
}