Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Unified Diff: sdk/lib/io/file_impl.dart

Issue 1193653002: Add file modes for opening a file write only (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Addressed review comments + fixed analyzer reported issues Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/file.dart ('k') | tests/standalone/io/file_write_only_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/file_impl.dart
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
index a98d9482671625458ab35b7995bf7b0b9b3d5fb1..8ed6c58b89b8b0d07327ac5c6c030bde19de9851 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -344,8 +344,11 @@ class _File extends FileSystemEntity implements File {
Future<RandomAccessFile> open({FileMode mode: FileMode.READ}) {
if (mode != FileMode.READ &&
mode != FileMode.WRITE &&
- mode != FileMode.APPEND) {
- return new Future.error(new ArgumentError());
+ mode != FileMode.APPEND &&
+ mode != FileMode.WRITE_ONLY &&
+ mode != FileMode.WRITE_ONLY_APPEND) {
+ return new Future.error(
+ new ArgumentError('Invalid file mode for this operation'));
}
return _IOService._dispatch(_FILE_OPEN, [path, mode._mode])
.then((response) {
@@ -401,10 +404,10 @@ class _File extends FileSystemEntity implements File {
RandomAccessFile openSync({FileMode mode: FileMode.READ}) {
if (mode != FileMode.READ &&
mode != FileMode.WRITE &&
- mode != FileMode.APPEND) {
- throw new FileSystemException("Unknown file mode. Use FileMode.READ, "
- "FileMode.WRITE or FileMode.APPEND.",
- path);
+ mode != FileMode.APPEND &&
+ mode != FileMode.WRITE_ONLY &&
+ mode != FileMode.WRITE_ONLY_APPEND) {
+ throw new ArgumentError('Invalid file mode for this operation');
}
var id = _open(path, mode._mode);
throwIfError(id, "Cannot open file", path);
@@ -428,9 +431,10 @@ class _File extends FileSystemEntity implements File {
IOSink openWrite({FileMode mode: FileMode.WRITE,
Encoding encoding: UTF8}) {
if (mode != FileMode.WRITE &&
- mode != FileMode.APPEND) {
- throw new ArgumentError(
- "Wrong FileMode. Use FileMode.WRITE or FileMode.APPEND");
+ mode != FileMode.APPEND &&
+ mode != FileMode.WRITE_ONLY &&
+ mode != FileMode.WRITE_ONLY_APPEND) {
+ throw new ArgumentError('Invalid file mode for this operation');
}
var consumer = new _FileStreamConsumer(this, mode);
return new IOSink(consumer, encoding: encoding);
« no previous file with comments | « sdk/lib/io/file.dart ('k') | tests/standalone/io/file_write_only_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698