writeToFile method

Future<void> writeToFile(
  1. String filePath
)

Implementation

Future<void> writeToFile(String filePath) async {
  final file = File(filePath);
  try {
    if (file.existsSync())
      file.deleteSync(); // Ensure we flush the file to 0 bytes
  } catch (E) {
    // If it fails then it fails, just fail silently, writing should still succeed.
  }

  var rac = await file.open(mode: FileMode.write);

  for (var byte in bytes) {
    await rac.writeByte(byte);
  }

  await rac.flush();
  await rac.close();
}