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

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

Issue 10065013: Support length operation without opening file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file.dart ('k') | runtime/bin/file_linux.cc » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class _FileInputStream extends _BaseDataInputStream implements InputStream { 5 class _FileInputStream extends _BaseDataInputStream implements InputStream {
6 _FileInputStream(String name) { 6 _FileInputStream(String name) {
7 _file = new File(name); 7 _file = new File(name);
8 _data = []; 8 _data = [];
9 _position = 0; 9 _position = 0;
10 _file.onError = (e) { 10 _file.onError = (e) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 static final kCreateRequest = 1; 210 static final kCreateRequest = 1;
211 static final kDeleteRequest = 2; 211 static final kDeleteRequest = 2;
212 static final kOpenRequest = 3; 212 static final kOpenRequest = 3;
213 static final kFullPathRequest = 4; 213 static final kFullPathRequest = 4;
214 static final kDirectoryRequest = 5; 214 static final kDirectoryRequest = 5;
215 static final kCloseRequest = 6; 215 static final kCloseRequest = 6;
216 static final kPositionRequest = 7; 216 static final kPositionRequest = 7;
217 static final kSetPositionRequest = 8; 217 static final kSetPositionRequest = 8;
218 static final kTruncateRequest = 9; 218 static final kTruncateRequest = 9;
219 static final kLengthRequest = 10; 219 static final kLengthRequest = 10;
220 static final kFlushRequest = 11; 220 static final kLengthFromNameRequest = 11;
221 static final kReadByteRequest = 12; 221 static final kFlushRequest = 12;
222 static final kWriteByteRequest = 13; 222 static final kReadByteRequest = 13;
223 static final kReadListRequest = 14; 223 static final kWriteByteRequest = 14;
224 static final kWriteListRequest = 15; 224 static final kReadListRequest = 15;
225 static final kWriteStringRequest = 16; 225 static final kWriteListRequest = 16;
226 static final kWriteStringRequest = 17;
226 227
227 static final kSuccessResponse = 0; 228 static final kSuccessResponse = 0;
228 static final kIllegalArgumentResponse = 1; 229 static final kIllegalArgumentResponse = 1;
229 static final kOSErrorResponse = 2; 230 static final kOSErrorResponse = 2;
230 static final kFileClosedResponse = 3; 231 static final kFileClosedResponse = 3;
231 232
232 static final kErrorResponseErrorType = 0; 233 static final kErrorResponseErrorType = 0;
233 static final kOSErrorResponseErrorCode = 1; 234 static final kOSErrorResponseErrorCode = 1;
234 static final kOSErrorResponseMessage = 2; 235 static final kOSErrorResponseMessage = 2;
235 236
(...skipping 22 matching lines...) Expand all
258 } 259 }
259 return [outBuffer, outOffset]; 260 return [outBuffer, outOffset];
260 } 261 }
261 262
262 static exists(String name) native "File_Exists"; 263 static exists(String name) native "File_Exists";
263 static open(String name, int mode) native "File_Open"; 264 static open(String name, int mode) native "File_Open";
264 static create(String name) native "File_Create"; 265 static create(String name) native "File_Create";
265 static delete(String name) native "File_Delete"; 266 static delete(String name) native "File_Delete";
266 static fullPath(String name) native "File_FullPath"; 267 static fullPath(String name) native "File_FullPath";
267 static directory(String name) native "File_Directory"; 268 static directory(String name) native "File_Directory";
269 static lengthFromName(String name) native "File_LengthFromName";
268 static int close(int id) native "File_Close"; 270 static int close(int id) native "File_Close";
269 static readByte(int id) native "File_ReadByte"; 271 static readByte(int id) native "File_ReadByte";
270 static readList(int id, List<int> buffer, int offset, int bytes) 272 static readList(int id, List<int> buffer, int offset, int bytes)
271 native "File_ReadList"; 273 native "File_ReadList";
272 static writeByte(int id, int value) native "File_WriteByte"; 274 static writeByte(int id, int value) native "File_WriteByte";
273 static writeList(int id, List<int> buffer, int offset, int bytes) { 275 static writeList(int id, List<int> buffer, int offset, int bytes) {
274 List result = 276 List result =
275 _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes); 277 _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes);
276 List outBuffer = result[0]; 278 List outBuffer = result[0];
277 int outOffset = result[1]; 279 int outOffset = result[1];
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 if (name is !String) { 349 if (name is !String) {
348 throw new IllegalArgumentException(); 350 throw new IllegalArgumentException();
349 } 351 }
350 var result = directory(name); 352 var result = directory(name);
351 if (result is OSError) { 353 if (result is OSError) {
352 throw new FileIOException("Cannot retrieve directory for file", result); 354 throw new FileIOException("Cannot retrieve directory for file", result);
353 } 355 }
354 return result; 356 return result;
355 } 357 }
356 358
359 static int checkedLengthFromName(String name) {
360 if (name is !String) {
361 throw new IllegalArgumentException();
362 }
363 var result = lengthFromName(name);
364 if (result is OSError) {
365 throw new FileIOException("Cannot retrieve length for file", result);
366 }
367 return result;
368 }
369
357 static int checkReadWriteListArguments(int length, int offset, int bytes) { 370 static int checkReadWriteListArguments(int length, int offset, int bytes) {
358 if (offset < 0) return offset; 371 if (offset < 0) return offset;
359 if (bytes < 0) return bytes; 372 if (bytes < 0) return bytes;
360 if ((offset + bytes) > length) return offset + bytes; 373 if ((offset + bytes) > length) return offset + bytes;
361 return 0; 374 return 0;
362 } 375 }
363 376
364 static int checkedWriteString(int id, String string) { 377 static int checkedWriteString(int id, String string) {
365 if (string is !String) return -1; 378 if (string is !String) return -1;
366 return writeString(id, string); 379 return writeString(id, string);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 request[2] = mode._mode; // Direct int value for serialization. 513 request[2] = mode._mode; // Direct int value for serialization.
501 _fileService.call(request).then((response) { 514 _fileService.call(request).then((response) {
502 if (_isErrorResponse(response)) { 515 if (_isErrorResponse(response)) {
503 _reportError(response, "Cannot open file"); 516 _reportError(response, "Cannot open file");
504 } else { 517 } else {
505 callback(new _RandomAccessFile(response, _name)); 518 callback(new _RandomAccessFile(response, _name));
506 } 519 }
507 }); 520 });
508 } 521 }
509 522
523 void length(void callback(int length)) {
524 _ensureFileService();
525 List request = new List(2);
526 request[0] = _FileUtils.kLengthFromNameRequest;
527 request[1] = _name;
528 _fileService.call(request).then((response) {
529 if (_isErrorResponse(response)) {
530 _reportError(response, "Cannot retrieve length for file");
531 } else {
532 callback(response);
533 }
534 });
535 }
536
537 int lengthSync() {
538 var result = _FileUtils.checkedLengthFromName(_name);
539 if (result is OSError) {
540 throw new FileIOException("Cannot retrieve lenght for file", result);
Søren Gjesse 2012/04/12 11:41:44 lenght -> length for -> of
Mads Ager (google) 2012/04/13 12:24:11 Done.
541 }
542 return result;
543 }
544
510 RandomAccessFile openSync([FileMode mode = FileMode.READ]) { 545 RandomAccessFile openSync([FileMode mode = FileMode.READ]) {
511 if (mode != FileMode.READ && 546 if (mode != FileMode.READ &&
512 mode != FileMode.WRITE && 547 mode != FileMode.WRITE &&
513 mode != FileMode.APPEND) { 548 mode != FileMode.APPEND) {
514 throw new FileIOException("Unknown file mode. Use FileMode.READ, " 549 throw new FileIOException("Unknown file mode. Use FileMode.READ, "
515 "FileMode.WRITE or FileMode.APPEND."); 550 "FileMode.WRITE or FileMode.APPEND.");
516 } 551 }
517 var id = _FileUtils.checkedOpen(_name, mode._mode); 552 var id = _FileUtils.checkedOpen(_name, mode._mode);
518 assert(id != 0); 553 assert(id != 0);
519 return new _RandomAccessFile(id, _name); 554 return new _RandomAccessFile(id, _name);
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 String _name; 1054 String _name;
1020 int _id; 1055 int _id;
1021 int _pendingWrites = 0; 1056 int _pendingWrites = 0;
1022 1057
1023 SendPort _fileService; 1058 SendPort _fileService;
1024 1059
1025 Timer _noPendingWriteTimer; 1060 Timer _noPendingWriteTimer;
1026 1061
1027 Function _onNoPendingWrites; 1062 Function _onNoPendingWrites;
1028 } 1063 }
OLDNEW
« no previous file with comments | « runtime/bin/file.dart ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698