writeAsBytes method
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();
}
}