OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 // Read the file in blocks of size 64k. | 7 // Read the file in blocks of size 64k. |
8 const int _BLOCK_SIZE = 64 * 1024; | 8 const int _BLOCK_SIZE = 64 * 1024; |
9 | 9 |
10 | 10 |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 File copySync(String newPath) { | 338 File copySync(String newPath) { |
339 var result = _copy(path, newPath); | 339 var result = _copy(path, newPath); |
340 throwIfError(result, "Cannot copy file to '$newPath'", path); | 340 throwIfError(result, "Cannot copy file to '$newPath'", path); |
341 return new File(newPath); | 341 return new File(newPath); |
342 } | 342 } |
343 | 343 |
344 Future<RandomAccessFile> open({FileMode mode: FileMode.READ}) { | 344 Future<RandomAccessFile> open({FileMode mode: FileMode.READ}) { |
345 if (mode != FileMode.READ && | 345 if (mode != FileMode.READ && |
346 mode != FileMode.WRITE && | 346 mode != FileMode.WRITE && |
347 mode != FileMode.APPEND) { | 347 mode != FileMode.APPEND && |
348 return new Future.error(new ArgumentError()); | 348 mode != FileMode.WRITE_ONLY && |
| 349 mode != FileMode.WRITE_ONLY_APPEND) { |
| 350 return new Future.error( |
| 351 new ArgumentError('Invalid file mode for this operation')); |
349 } | 352 } |
350 return _IOService._dispatch(_FILE_OPEN, [path, mode._mode]) | 353 return _IOService._dispatch(_FILE_OPEN, [path, mode._mode]) |
351 .then((response) { | 354 .then((response) { |
352 if (_isErrorResponse(response)) { | 355 if (_isErrorResponse(response)) { |
353 throw _exceptionFromResponse(response, "Cannot open file", path); | 356 throw _exceptionFromResponse(response, "Cannot open file", path); |
354 } | 357 } |
355 return new _RandomAccessFile(response, path); | 358 return new _RandomAccessFile(response, path); |
356 }); | 359 }); |
357 } | 360 } |
358 | 361 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 var ms = _lastModified(path); | 397 var ms = _lastModified(path); |
395 throwIfError(ms, "Cannot retrieve modification time", path); | 398 throwIfError(ms, "Cannot retrieve modification time", path); |
396 return new DateTime.fromMillisecondsSinceEpoch(ms); | 399 return new DateTime.fromMillisecondsSinceEpoch(ms); |
397 } | 400 } |
398 | 401 |
399 external static _open(String path, int mode); | 402 external static _open(String path, int mode); |
400 | 403 |
401 RandomAccessFile openSync({FileMode mode: FileMode.READ}) { | 404 RandomAccessFile openSync({FileMode mode: FileMode.READ}) { |
402 if (mode != FileMode.READ && | 405 if (mode != FileMode.READ && |
403 mode != FileMode.WRITE && | 406 mode != FileMode.WRITE && |
404 mode != FileMode.APPEND) { | 407 mode != FileMode.APPEND && |
405 throw new FileSystemException("Unknown file mode. Use FileMode.READ, " | 408 mode != FileMode.WRITE_ONLY && |
406 "FileMode.WRITE or FileMode.APPEND.", | 409 mode != FileMode.WRITE_ONLY_APPEND) { |
407 path); | 410 throw new ArgumentError('Invalid file mode for this operation'); |
408 } | 411 } |
409 var id = _open(path, mode._mode); | 412 var id = _open(path, mode._mode); |
410 throwIfError(id, "Cannot open file", path); | 413 throwIfError(id, "Cannot open file", path); |
411 return new _RandomAccessFile(id, path); | 414 return new _RandomAccessFile(id, path); |
412 } | 415 } |
413 | 416 |
414 external static int _openStdio(int fd); | 417 external static int _openStdio(int fd); |
415 | 418 |
416 static RandomAccessFile _openStdioSync(int fd) { | 419 static RandomAccessFile _openStdioSync(int fd) { |
417 var id = _openStdio(fd); | 420 var id = _openStdio(fd); |
418 if (id == 0) { | 421 if (id == 0) { |
419 throw new FileSystemException("Cannot open stdio file for: $fd"); | 422 throw new FileSystemException("Cannot open stdio file for: $fd"); |
420 } | 423 } |
421 return new _RandomAccessFile(id, ""); | 424 return new _RandomAccessFile(id, ""); |
422 } | 425 } |
423 | 426 |
424 Stream<List<int>> openRead([int start, int end]) { | 427 Stream<List<int>> openRead([int start, int end]) { |
425 return new _FileStream(path, start, end); | 428 return new _FileStream(path, start, end); |
426 } | 429 } |
427 | 430 |
428 IOSink openWrite({FileMode mode: FileMode.WRITE, | 431 IOSink openWrite({FileMode mode: FileMode.WRITE, |
429 Encoding encoding: UTF8}) { | 432 Encoding encoding: UTF8}) { |
430 if (mode != FileMode.WRITE && | 433 if (mode != FileMode.WRITE && |
431 mode != FileMode.APPEND) { | 434 mode != FileMode.APPEND && |
432 throw new ArgumentError( | 435 mode != FileMode.WRITE_ONLY && |
433 "Wrong FileMode. Use FileMode.WRITE or FileMode.APPEND"); | 436 mode != FileMode.WRITE_ONLY_APPEND) { |
| 437 throw new ArgumentError('Invalid file mode for this operation'); |
434 } | 438 } |
435 var consumer = new _FileStreamConsumer(this, mode); | 439 var consumer = new _FileStreamConsumer(this, mode); |
436 return new IOSink(consumer, encoding: encoding); | 440 return new IOSink(consumer, encoding: encoding); |
437 } | 441 } |
438 | 442 |
439 Future<List<int>> readAsBytes() { | 443 Future<List<int>> readAsBytes() { |
440 Future<List<int>> readDataChunked(file) { | 444 Future<List<int>> readDataChunked(file) { |
441 var builder = new BytesBuilder(copy: false); | 445 var builder = new BytesBuilder(copy: false); |
442 var completer = new Completer(); | 446 var completer = new Completer(); |
443 void read() { | 447 void read() { |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 void _checkAvailable() { | 1042 void _checkAvailable() { |
1039 if (_asyncDispatched) { | 1043 if (_asyncDispatched) { |
1040 throw new FileSystemException("An async operation is currently pending", | 1044 throw new FileSystemException("An async operation is currently pending", |
1041 path); | 1045 path); |
1042 } | 1046 } |
1043 if (closed) { | 1047 if (closed) { |
1044 throw new FileSystemException("File closed", path); | 1048 throw new FileSystemException("File closed", path); |
1045 } | 1049 } |
1046 } | 1050 } |
1047 } | 1051 } |
OLD | NEW |