writeAt method

  1. @override
Future<void> writeAt(
  1. int offset,
  2. List<int> bytes
)
override

Replaces existing bytes beginning at offset without changing the length.

Implementation

@override
Future<void> writeAt(int offset, List<int> bytes) => _synchronized(() async {
  _validateBytes(bytes);
  final range = ByteRange.fromStartAndLength(offset, bytes.length);
  final available = ByteRange(0, _length);
  if (!available.containsRange(range)) {
    throw ByteRangeOutOfBoundsException(range, available);
  }
  try {
    await _handle.setPosition(offset);
    await _handle.writeFrom(bytes);
  } on FileSystemException catch (error) {
    throw ByteSinkIoException(
      operation: 'patch bytes',
      cause: error,
      location: _staging.path,
    );
  }
});