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

Unified Diff: runtime/bin/file.dart

Issue 9500002: Rename blahHandler to onBlah throughout dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 10 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 | « runtime/bin/directory_impl.dart ('k') | runtime/bin/file_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file.dart
diff --git a/runtime/bin/file.dart b/runtime/bin/file.dart
index 8b36398de65da86d82731cea87e09aea0da6955f..9728ab7cd92d338429781fb34974419b3fc74f25 100644
--- a/runtime/bin/file.dart
+++ b/runtime/bin/file.dart
@@ -29,10 +29,11 @@ interface File default _File {
File(String name);
/**
- * Check if the file exists. The [existsHandler] is called with the
- * result when the operation completes.
+ * Check if the file exists. The callback is called with the result
+ * when the operation completes. The [onError] function registered
+ * on the file object is called if an error occurs.
*/
- void exists();
+ void exists(void callback(bool exists));
/**
* Synchronously check if the file exists.
@@ -40,13 +41,13 @@ interface File default _File {
bool existsSync();
/**
- * Create the file. The [createHandler] is called when the file has
- * been created. The [errorHandler] is called if the file cannot be
- * created. Existing files are left untouched by create. Calling
- * create on an existing file might fail if there are restrictive
- * permissions on the file.
+ * Create the file. The callback is called when the file has been
+ * created. The [onError] function registered on the file object is
+ * called if the file cannot be created. Existing files are left
+ * untouched by create. Calling create on an existing file might
+ * fail if there are restrictive permissions on the file.
*/
- void create();
+ void create(void callback());
/**
* Synchronously create the file. Existing files are left untouched
@@ -56,11 +57,11 @@ interface File default _File {
void createSync();
/**
- * Delete the file. The [deleteHandler] is called when the file has
- * been successfully deleted. The [errorHandler] is called if the
- * file cannot be deleted.
+ * Delete the file. The callback is called when the file has been
+ * successfully deleted. The [onError] function registered on the
+ * file object is called if the file cannot be deleted.
*/
- void delete();
+ void delete(void callback());
/**
* Synchronously delete the file.
@@ -68,12 +69,12 @@ interface File default _File {
void deleteSync();
/**
- * Get a Directory object for the directory containing this file. If
- * the file does not exist the [errorHandler] is called. When the
- * operation completes the [directoryHandler] is called with the
- * result.
+ * Get a Directory object for the directory containing this
+ * file. When the operation completes the callback is called with
+ * the result. If the file does not exist the [onError] function
+ * registered on the file object is called.
*/
- void directory();
+ void directory(void callback(Directory dir));
/**
* Synchronously get a Directory object for the directory containing
@@ -83,15 +84,14 @@ interface File default _File {
/**
* Open the file for random access operations. When the file is
- * opened the [openHandler] is called with the resulting
+ * opened the callback is called with the resulting
* RandomAccessFile. RandomAccessFiles must be closed using the
- * [close] method. If the file cannot be opened the [errorHandler]
- * is called.
+ * [close] method. If the file cannot be opened [onError] is called.
*
* Files can be opened in three modes:
*
* FileMode.READ: open the file for reading. If the file does not
- * exist the [errorHandler] is called.
+ * exist [onError] is called.
*
* FileMode.WRITE: open the file for both reading and writing and
* truncate the file to length zero. If the file does not exist the
@@ -99,10 +99,8 @@ interface File default _File {
*
* FileMode.APPEND: same as FileMode.WRITE except that the file is
* not truncated.
- *
- * By default mode is FileMode.READ.
*/
- void open([FileMode mode]);
+ void open(FileMode mode, void callback(RandomAccessFile opened));
/**
* Synchronously open the file for random access operations. The
@@ -112,14 +110,15 @@ interface File default _File {
*
* See [open] for information on the [:mode:] argument.
*/
- RandomAccessFile openSync([FileMode mode]);
+ RandomAccessFile openSync(FileMode mode);
/**
- * Get the canonical full path corresponding to the file name. The
- * [fullPathHandler] is called with the result when the fullPath
- * operation completes.
+ * Get the canonical full path corresponding to the file name. The
+ * callback is called with the result when the
+ * fullPath operation completes. If the operation fails the
+ * [onError] function registered on the file object is called.
*/
- void fullPath();
+ void fullPath(void callback(String path));
/**
* Synchronously get the canonical full path corresponding to the file name.
@@ -152,10 +151,11 @@ interface File default _File {
/**
* Read the entire file contents as a list of bytes. When the
- * operation completes the [readAsBytesHandler] is called.
- * The [errorHandler] is called if the operation fails.
+ * operation completes the callback is called. The [onError]
+ * function registered on the file object is called if the operation
+ * fails.
*/
- void readAsBytes();
+ void readAsBytes(void callback(List<int> bytes));
/**
* Synchronously read the entire file contents as a list of bytes.
@@ -164,14 +164,13 @@ interface File default _File {
/**
* Read the entire file contents as text using the given [encoding]
- * ('UTF-8', 'ISO-8859-1', 'ASCII'). By default the encoding is
- * 'UTF-8'.
+ * ('UTF-8', 'ISO-8859-1', 'ASCII').
*
- * When the operation completes the [readAsTextHandler] is called
- * with the resulting string. The [errorHandler] is called if the
+ * When the operation completes the callback is called. The
+ * [onError] function registered on the file object is called if the
* operation fails.
*/
- void readAsText([String encoding]);
+ void readAsText(String encoding, void callback(String text));
/**
* Synchronously read the entire file contents as text using the
@@ -182,14 +181,13 @@ interface File default _File {
/**
* Read the entire file contents as lines of text using the give
- * [encoding] ('UTF-8', 'ISO-8859-1', 'ASCII'). By default the
- * encoding is 'UTF-8'.
+ * [encoding] ('UTF-8', 'ISO-8859-1', 'ASCII').
*
- * When the operation completes the [readAsLinesHandler] is called
- * with the resulting string. The [errorHandler] is called if the
+ * When the operation completes the callback is called. The
+ * [onError] function registered on the file object is called if the
* operation fails.
*/
- void readAsLines();
+ void readAsLines(String encoding, void callback(List<String> lines));
/**
* Synchronously read the entire file contents as lines of text
@@ -204,64 +202,10 @@ interface File default _File {
String get name();
/**
- * Sets the handler that gets called when an [exists] operation
- * completes.
- */
- void set existsHandler(void handler(bool exists));
-
- /**
- * Sets the handler that gets called when a [create] operation
- * completes.
- */
- void set createHandler(void handler());
-
- /**
- * Sets the handler that gets called when a [delete] operation
- * completes.
- */
- void set deleteHandler(void handler());
-
- /**
- * Sets the handler that gets called when a [directory] operation
- * completes.
- */
- void set directoryHandler(void handler(Directory directory));
-
- /**
- * Sets the handler that gets called when an [open] operation
- * completes.
- */
- void set openHandler(void handler(RandomAccessFile openedFile));
-
- /**
- * Set the handler that gets called when a [readAsBytes] operation
- * completes.
- */
- void set readAsBytesHandler(void handler(List<int> bytes));
-
- /**
- * Set the handler that gets called when a [readAsText] operation
- * completes.
- */
- void set readAsTextHandler(void handler(String text));
-
- /**
- * Set the handler that gets called when a [readAsLines] operation
- * completes.
- */
- void set readAsLinesHandler(void handler(List<String> lines));
-
- /**
- * Sets the handler that gets called when a [fullPath] operation
- * completes.
- */
- void set fullPathHandler(void handler(String path));
-
- /**
* Sets the handler that gets called when errors occur during
* operations on this file.
*/
- void set errorHandler(void handler(String error));
+ void set onError(void handler(String error));
}
@@ -272,10 +216,9 @@ interface File default _File {
*/
interface RandomAccessFile {
/**
- * Close the file. When the file is closed the [closeHandler] is
- * called.
+ * Close the file. When the file is closed the callback is called.
*/
- void close();
+ void close(void callback());
/**
* Synchronously close the file.
@@ -284,9 +227,9 @@ interface RandomAccessFile {
/**
* Read a byte from the file. When the byte has been read the
- * [readByteHandler] is called with the value.
+ * callback is called with the value.
*/
- void readByte();
+ void readByte(void callback(int byte));
/**
* Synchronously read a single byte from the file.
@@ -295,10 +238,10 @@ interface RandomAccessFile {
/**
* Read a List<int> from the file. When the list has been read the
- * [readListHandler] is called with an integer indicating how much
- * was read.
+ * callback is called with an integer indicating how much was read.
*/
- void readList(List<int> buffer, int offset, int bytes);
+ void readList(List<int> buffer, int offset, int bytes,
+ void callback(int read));
/**
* Synchronously read a List<int> from the file. Returns the number
@@ -308,8 +251,8 @@ interface RandomAccessFile {
/**
* Write a single byte to the file. If the byte cannot be written
- * the [errorHandler] is called. When all pending write operations
- * have finished the [noPendingWriteHandler] is called.
+ * [onError] is called. When all pending write operations have
+ * finished [onNoPendingWrites] is called.
*/
void writeByte(int value);
@@ -321,8 +264,8 @@ interface RandomAccessFile {
/**
* Write a List<int> to the file. If the list cannot be written the
- * [errorHandler] is called. When all pending write operations have
- * finished the [noPendingWriteHandler] is called.
+ * [onError] is called. When all pending write operations have
+ * finished [onNoPendingWrites] is called.
*/
void writeList(List<int> buffer, int offset, int bytes);
@@ -334,8 +277,8 @@ interface RandomAccessFile {
/**
* Write a string to the file. If the string cannot be written the
- * [errorHandler] is called. When all pending write operations have
- * finished the [noPendingWriteHandler] is called.
+ * [onError] is called. When all pending write operations have
+ * finished [onNoPendingWrites] is called.
*/
// TODO(ager): writeString should take an encoding.
void writeString(String string);
@@ -349,9 +292,9 @@ interface RandomAccessFile {
/**
* Get the current byte position in the file. When the operation
- * completes the [positionHandler] is called with the position.
+ * completes the callback is called with the position.
*/
- void position();
+ void position(void callback(int position));
/**
* Synchronously get the current byte position in the file.
@@ -360,9 +303,9 @@ interface RandomAccessFile {
/**
* Set the byte position in the file. When the operation completes
- * the [setPositionHandler] is called.
+ * the callback is called.
*/
- void setPosition(int position);
+ void setPosition(int position, void callback());
/**
* Synchronously set the byte position in the file.
@@ -371,9 +314,9 @@ interface RandomAccessFile {
/**
* Truncate (or extend) the file to [length] bytes. When the
- * operation completes successfully the [truncateHandler] is called.
+ * operation completes successfully the callback is called.
*/
- void truncate(int length);
+ void truncate(int length, void callback());
/**
* Synchronously truncate (or extend) the file to [length] bytes.
@@ -382,9 +325,9 @@ interface RandomAccessFile {
/**
* Get the length of the file. When the operation completes the
- * [lengthHandler] is called with the length.
+ * callback is called with the length.
*/
- void length();
+ void length(void callback(int length));
/**
* Synchronously get the length of the file.
@@ -392,10 +335,10 @@ interface RandomAccessFile {
int lengthSync();
/**
- * Flush the contents of the file to disk. The [flushHandler] is
+ * Flush the contents of the file to disk. The callback is
* called when the flush operation completes.
*/
- void flush();
+ void flush(void callback());
/**
* Synchronously flush the contents of the file to disk.
@@ -408,64 +351,16 @@ interface RandomAccessFile {
String get name();
/**
- * Sets the handler that gets called when a [close] operation
- * completes.
- */
- void set closeHandler(void handler());
-
- /**
- * Sets the handler that gets called when a [readByte] operation
- * completes.
- */
- void set readByteHandler(void handler(int byte));
-
- /**
- * Sets the handler that gets called when a [readList] operation
- * completes.
- */
- void set readListHandler(void handler(int read));
-
- /**
* Sets the handler that gets called when there are no more write
* operations pending for this file.
*/
- void set noPendingWriteHandler(void handler());
-
- /**
- * Sets the handler that gets called when a [position] operation
- * completes.
- */
- void set positionHandler(void handler(int position));
-
- /**
- * Sets the handler that gets called when a [setPosition] operation
- * completes.
- */
- void set setPositionHandler(void handler());
-
- /**
- * Sets the handler that gets called when a [truncate] operation
- * completes.
- */
- void set truncateHandler(void handler());
-
- /**
- * Sets the handler that gets called when a [length] operation
- * completes.
- */
- void set lengthHandler(void handler(int length));
-
- /**
- * Sets the handler that gets called when a [flush] operation
- * completes.
- */
- void set flushHandler(void handler());
+ void set onNoPendingWrites(void handler());
/**
* Sets the handler that gets called when errors occur when
* operating on this file.
*/
- void set errorHandler(void handler(String error));
+ void set onError(void handler(String error));
}
« no previous file with comments | « runtime/bin/directory_impl.dart ('k') | runtime/bin/file_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698