-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
please add an option to File.writeAsBytes
to avoid overwriting.
#59587
Comments
Summary: User requests |
What behavior do you expect in case the file already exists? Throw exception? |
@julemand101 yes |
Have you looked at https://api.dart.dev/dart-io/File/create.html which allows you to specify |
From my understanding create guarantee you to create the file, but from my understanding File is not a file descriptor so now that the file is created overwrite can still happens |
@stephane-archer AFAIK there is no way to prevent that in POSIX though - if the other program does not take precautions (e.g. does not use |
@mraleph there is no way to ask for exclusive access until the file is closed on POSIX? |
@stephane-archer not to the best of my knowledge. there are file locks but they are advisory (so writers should all cooperate and use them - write operations themselves don't check locks). Mandatory locks API kinda sorta exists - but not really, see |
Thanks for your answers So the best we have right know in Dart to write data without overwrite is: var file = await File("a.txt").create(recursive : false,
exclusive: true,
})
file.writeAsBytes(data); I think it would be still nice to have a short version for this: await File("a.txt").writeAsBytes(data, exclusive: true);
// or
File("a.txt", exclusive: true).writeAsBytes(data);
|
please add an option to
File.writeAsBytes
to avoid overwriting.maybe something like
await outputFile.writeAsBytes(jpegData, exclusive: true);
The text was updated successfully, but these errors were encountered: