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

Side by Side Diff: runtime/bin/file.dart

Issue 8399033: First round of changes to the file interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file.cc ('k') | runtime/bin/file_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 interface File factory _File { 5 interface File factory _File {
6 // Open a file. 6 /**
7 File(String name, bool writable); 7 * Create a File object.
8 8 */
9 // Close the file. 9 File(String name);
10
11 /**
12 * Check if the file exists. The [existsHandler] is called with the
13 * result when the operation completes.
14 */
15 void exists();
16
17 /**
18 * Synchronously check if the file exists.
19 */
20 bool existsSync();
21
22 /**
23 * Create the file. The [createHandler] is called when the file has
24 * been created. The errorHandler is called if the file cannot be
25 * created.
26 */
27 void create();
28
29 /**
30 * Synchronously create the file.
31 */
32 void createSync();
33
34 /**
35 * Open the file for random access operations. When the file is
36 * opened the openHandler is called. Opened files must be closed
37 * using the [close] method. By default writable is false.
38 */
39 void open([bool writable]);
40
41 /**
42 * Synchronously open the file for random access operations. Opened
43 * files must be closed using the [close] method. By default
44 * writable is false.
45 */
46 void openSync([bool writable]);
47
48 /**
49 * Close the file. When the file is closed the closeHandler is
50 * called.
51 */
10 void close(); 52 void close();
11 53
12 // Synchronously read a single byte from the file. 54 /**
13 // TODO(jrgfogh): Remove this call. 55 * Synchronously close the file.
14 int readByte(); 56 */
15 57 void closeSync();
16 // Synchronously write a single byte to the file. 58
17 // TODO(jrgfogh): Remove this call. 59 /**
18 int writeByte(int value); 60 * Read a byte from the file. When the byte has been read the
19 61 * [readByteHandler] is called with the value.
20 // Synchronously write a single string to the file. 62 */
21 // TODO(jrgfogh): Remove this call. 63 void readByte();
22 int writeString(String string); 64
23 65 /**
24 // Synchronously read a List<int> from the file. 66 * Synchronously read a single byte from the file.
25 // TODO(jrgfogh): Remove this call. 67 */
26 int readList(List<int> buffer, int offset, int bytes); 68 int readByteSync();
27 69
28 // Synchronously write a List<int> to the file. 70 /**
29 // TODO(jrgfogh): Remove this call. 71 * Read a List<int> from the file. When the list has been read the
30 int writeList(List<int> buffer, int offset, int bytes); 72 * [readListHandler] is called with an integer indicating how much
31 73 * was read.
32 // The current position of the file handle. 74 */
33 int get position(); 75 void readList(List<int> buffer, int offset, int bytes);
34 76
35 // The length of the file. 77 /**
36 int get length(); 78 * Synchronously read a List<int> from the file. Returns the number
37 79 * of bytes read.
38 // Flush the contents of the file to disk. 80 */
39 void flush(); 81 int readListSync(List<int> buffer, int offset, int bytes);
40 82
41 // Each file has an unique InputStream. 83 /**
42 InputStream get inputStream(); 84 * Write a single byte to the file. If the byte cannot be written
43 85 * the [errorHandler] is called. When all pending write operations
44 // Each file has an unique OutputStream. 86 * have finished the [noPendingWriteHandler] is called.
45 OutputStream get outputStream(); 87 */
46 } 88 void writeByte(int value);
47 89
48 90 /**
49 class FileUtil { 91 * Synchronously write a single byte to the file. Returns true if
50 static bool fileExists(String name) native "File_Exists"; 92 * the byte was successfully written and false otherwise.
93 */
94 bool writeByteSync(int value);
95
96 /**
97 * Write a List<int> to the file. If the list cannot be written the
98 * [errorHandler] is called. When all pending write operations have
99 * finished the [noPendingWriteHandler] is called.
100 */
101 void writeList(List<int> buffer, int offset, int bytes);
102
103 /**
104 * Synchronously write a List<int> to the file. Returns true if the
105 * list was successfully written and false otherwise.
106 */
107 bool writeListSync(List<int> buffer, int offset, int bytes);
108
109 /**
110 * Write a string to the file. If the string cannot be written the
111 * [errorHandler] is called. When all pending write operations have
112 * finished the [noPendingWriteHandler] is called.
113 */
114 // TODO(ager): writeString should take an encoding.
115 void writeString(String string);
116
117 /**
118 * Synchronously write a single string to the file. Returns true if
119 * the string was successfully written and false otherwise.
120 */
121 // TODO(ager): writeStringSync should take an encoding.
122 bool writeStringSync(String string);
123
124 /**
125 * Get the current position of the file. When the operation
126 * completes the [positionHandler] is called with the position.
127 */
128 void position();
129
130 /**
131 * Synchronously get the current position of the file.
132 */
133 int positionSync();
134
135 /**
136 * Get the length of the file. When the operation completes the
137 * [lengthHandler] is called with the length.
138 */
139 void length();
140
141 /**
142 * Get the length of the file. When the operation completes the
143 * [lengthHandler] is called with the length.
144 */
145 int lengthSync();
146
147 /**
148 * Flush the contents of the file to disk. If there are no pending
149 * write operation after the flush operation completes, the
150 * [noPendingWriteHandler] is called.
151 */
152 void flush();
153
154 /**
155 * Synchronously flush the contents of the file to disk.
156 */
157 void flushSync();
158
159 /**
160 * Create a new independent input stream for the file. The file
161 * input stream must be closed when no longer used.
162 */
163 FileInputStream openInputStream();
164
165 /**
166 * Creates a new independent output stream for the file. The file
167 * output stream must be closed when no longer used.
168 */
169 FileOutputStream openOutputStream();
170
171 /**
172 * Get the name of the file.
173 */
174 String get name();
175
176 // Event handlers.
177 void set existsHandler(void handler(bool exists));
178 void set createHandler(void handler());
179 void set openHandler(void handler());
180 void set closeHandler(void handler());
181 void set readByteHandler(void handler(int byte));
182 void set readListHandler(void handler(int read));
183 void set noPendingWriteHandler(void handler());
184 void set errorHandler(void handler(String error));
185 }
186
187
188 interface FileInputStream extends InputStream {
189 void close();
190 }
191
192
193 interface FileOutputStream extends OutputStream {
194 void close();
51 } 195 }
52 196
53 197
54 class FileIOException implements Exception { 198 class FileIOException implements Exception {
55 const FileIOException([String this.message = ""]); 199 const FileIOException([String this.message = ""]);
56 String toString() => "FileIOException: $message"; 200 String toString() => "FileIOException: $message";
57
58 /*
59 * Contains the exception message.
60 */
61 final String message; 201 final String message;
62 } 202 }
OLDNEW
« no previous file with comments | « runtime/bin/file.cc ('k') | runtime/bin/file_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698