writeBytes static method
Writes content to target atomically.
Writes to a .partial file in the same directory, then renames
to the final path. The rename is atomic on POSIX systems and
effectively atomic on Windows (best-effort).
Implementation
static Future<void> writeBytes(File target, List<int> content) async {
final tmp = File('${target.path}.partial');
try {
await tmp.writeAsBytes(content, flush: true);
tmp.renameSync(target.path);
} finally {
if (tmp.existsSync()) tmp.deleteSync();
}
}