incrementBytesWritten method

void incrementBytesWritten(
  1. int amount
)

Update the write position by amount bytes.

Bumps the internal writeCount pointer by an amount. If amount is negative, a RangeError is thrown. If the additional write by an amount overflows the buffer, a ArgumentError is thrown.

Implementation

void incrementBytesWritten(int amount) {
  RangeError.checkNotNegative(amount);
  final nextWrite = writeCount + amount;
  if (nextWrite > length) {
    final overWritten = nextWrite - length;
    final bytes = overWritten == 1 ? 'byte' : 'bytes';
    throw ArgumentError(
        'illegal attempt to write $overWritten $bytes past the buffer');
  } else {
    writeCount = nextWrite;
  }
}