There are a number of sync and async operations for files in dart:io
:
file.deleteSync()
and file.delete()
file.readAsStringSync()
and file.readAsString()
file.writeAsBytesSync(bytes)
and file.writeAsBytes(bytes)
What are the considerations that I should keep in mind when choosing between the sync and async options? I seem to recall seeing somewhere that the sync option is faster if you have to wait for it to finish anyway (await file.delete()
for example). But I can't remember where I saw that or if it is true.
Is there any difference between this method:
Future deleteFile(File file) async {
await file.delete();
print('deleted');
}
and this method:
Future deleteFile(File file) async {
file.deleteSync();
print('deleted');
}
Let me try to summarize an answer based on the comments to my question. Correct me where I'm wrong.
async
method doesn't make it run on another thread.compute
and IsolateChannel
and writing your own isolate communication code.file.exists()
?), using the synchronous version is an option since it is likely to be fast.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With