truncate method

  1. @override
Future<void> truncate(
  1. int newLength
)
override

Resizes the container to newLength bytes (shrinking discards tail bytes).

Implementation

@override
Future<void> truncate(int newLength) {
  if (newLength < 0) {
    return Future<void>.error(
      RangeError.value(newLength, 'newLength', 'Must be non-negative'),
    );
  }
  if (readOnly) {
    return Future<void>.error(const WalPackReadOnlyException());
  }
  return _ioMutex.synchronized(() async {
    final raf = _requireOpen();
    try {
      _knownPos = -1;
      if (ioMode != .async) {
        raf.truncateSync(newLength);
      } else {
        await raf.truncate(newLength);
      }
    } finally {
      _releaseIfTransient();
    }
  });
}