writeAt method
Implementation
@override
Future<void> writeAt(int position, List<int> bytes) async {
int offset = 0;
while (offset < bytes.length) {
final int absolute = position + offset;
final int index = absolute ~/ chunkSize;
final int within = absolute % chunkSize;
final _PendingChunk chunk = _pending.putIfAbsent(index, () => _PendingChunk(chunkSize));
if (within != chunk.filled) throw StateError("Vault chunk $index must be written sequentially.");
final int take = min(chunkSize - within, bytes.length - offset);
chunk.bytes.setRange(within, within + take, bytes, offset);
chunk.filled += take;
offset += take;
final int? known = _knownLength;
final bool isLast = known != null && (index + 1) * chunkSize >= known;
if (chunk.filled == chunkSize || (isLast && index * chunkSize + chunk.filled == known)) {
await _seal(index, chunk.filled, last: isLast);
}
}
}