writeAsBytes method

Future<File> writeAsBytes(
  1. File file,
  2. List<int> bytes, {
  3. FileMode mode = FileMode.write,
  4. bool flush = false,
})

Writes bytes to file with controlled concurrency.

Works like File.writeAsBytes, but uses the semaphore to avoid excessive parallel writes that could trigger system throttling or failures.

Implementation

Future<File> writeAsBytes(
  File file,
  List<int> bytes, {
  FileMode mode = FileMode.write,
  bool flush = false,
}) async {
  await _semaphore.acquire();
  try {
    return await file.writeAsBytes(bytes, mode: mode, flush: flush);
  } finally {
    _semaphore.release();
  }
}