OLD | NEW |
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 = (String s) { | 10 _file.onError = (String s) { |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 _asyncUsed = true; | 323 _asyncUsed = true; |
324 if (_name is !String) { | 324 if (_name is !String) { |
325 if (_onError != null) { | 325 if (_onError != null) { |
326 _onError('File name is not a string: $_name'); | 326 _onError('File name is not a string: $_name'); |
327 } | 327 } |
328 return; | 328 return; |
329 } | 329 } |
330 List request = new List(2); | 330 List request = new List(2); |
331 request[0] = _FileUtils.kExistsRequest; | 331 request[0] = _FileUtils.kExistsRequest; |
332 request[1] = _name; | 332 request[1] = _name; |
333 _fileService.call(request).receive((exists, replyTo) { | 333 _fileService.call(request).then((exists) { |
334 callback(exists); | 334 callback(exists); |
335 }); | 335 }); |
336 } | 336 } |
337 | 337 |
338 bool existsSync() { | 338 bool existsSync() { |
339 if (_asyncUsed) { | 339 if (_asyncUsed) { |
340 throw new FileIOException( | 340 throw new FileIOException( |
341 "Mixed use of synchronous and asynchronous API"); | 341 "Mixed use of synchronous and asynchronous API"); |
342 } | 342 } |
343 if (_name is !String) { | 343 if (_name is !String) { |
344 throw new FileIOException('File name is not a string: $_name'); | 344 throw new FileIOException('File name is not a string: $_name'); |
345 } | 345 } |
346 return _FileUtils.exists(_name); | 346 return _FileUtils.exists(_name); |
347 } | 347 } |
348 | 348 |
349 void create(void callback()) { | 349 void create(void callback()) { |
350 _ensureFileService(); | 350 _ensureFileService(); |
351 _asyncUsed = true; | 351 _asyncUsed = true; |
352 List request = new List(2); | 352 List request = new List(2); |
353 request[0] = _FileUtils.kCreateRequest; | 353 request[0] = _FileUtils.kCreateRequest; |
354 request[1] = _name; | 354 request[1] = _name; |
355 _fileService.call(request).receive((created, replyTo) { | 355 _fileService.call(request).then((created) { |
356 if (created) { | 356 if (created) { |
357 callback(); | 357 callback(); |
358 } else if (_onError != null) { | 358 } else if (_onError != null) { |
359 _onError("Cannot create file: $_name"); | 359 _onError("Cannot create file: $_name"); |
360 } | 360 } |
361 }); | 361 }); |
362 } | 362 } |
363 | 363 |
364 void createSync() { | 364 void createSync() { |
365 if (_asyncUsed) { | 365 if (_asyncUsed) { |
366 throw new FileIOException( | 366 throw new FileIOException( |
367 "Mixed use of synchronous and asynchronous API"); | 367 "Mixed use of synchronous and asynchronous API"); |
368 } | 368 } |
369 bool created = _FileUtils.checkedCreate(_name); | 369 bool created = _FileUtils.checkedCreate(_name); |
370 if (!created) { | 370 if (!created) { |
371 throw new FileIOException("Cannot create file: $_name"); | 371 throw new FileIOException("Cannot create file: $_name"); |
372 } | 372 } |
373 } | 373 } |
374 | 374 |
375 void delete(void callback()) { | 375 void delete(void callback()) { |
376 _ensureFileService(); | 376 _ensureFileService(); |
377 _asyncUsed = true; | 377 _asyncUsed = true; |
378 List request = new List(2); | 378 List request = new List(2); |
379 request[0] = _FileUtils.kDeleteRequest; | 379 request[0] = _FileUtils.kDeleteRequest; |
380 request[1] = _name; | 380 request[1] = _name; |
381 _fileService.call(request).receive((deleted, replyTo) { | 381 _fileService.call(request).then((deleted) { |
382 if (deleted) { | 382 if (deleted) { |
383 callback(); | 383 callback(); |
384 } else if (_onError != null) { | 384 } else if (_onError != null) { |
385 _onError("Cannot delete file: $_name"); | 385 _onError("Cannot delete file: $_name"); |
386 } | 386 } |
387 }); | 387 }); |
388 } | 388 } |
389 | 389 |
390 void deleteSync() { | 390 void deleteSync() { |
391 if (_asyncUsed) { | 391 if (_asyncUsed) { |
392 throw new FileIOException( | 392 throw new FileIOException( |
393 "Mixed use of synchronous and asynchronous API"); | 393 "Mixed use of synchronous and asynchronous API"); |
394 } | 394 } |
395 bool deleted = _FileUtils.checkedDelete(_name); | 395 bool deleted = _FileUtils.checkedDelete(_name); |
396 if (!deleted) { | 396 if (!deleted) { |
397 throw new FileIOException("Cannot delete file: $_name"); | 397 throw new FileIOException("Cannot delete file: $_name"); |
398 } | 398 } |
399 } | 399 } |
400 | 400 |
401 void directory(void callback(Directory dir)) { | 401 void directory(void callback(Directory dir)) { |
402 _ensureFileService(); | 402 _ensureFileService(); |
403 _asyncUsed = true; | 403 _asyncUsed = true; |
404 List request = new List(2); | 404 List request = new List(2); |
405 request[0] = _FileUtils.kDirectoryRequest; | 405 request[0] = _FileUtils.kDirectoryRequest; |
406 request[1] = _name; | 406 request[1] = _name; |
407 _fileService.call(request).receive((path, replyTo) { | 407 _fileService.call(request).then((path) { |
408 if (path != null) { | 408 if (path != null) { |
409 callback(new Directory(path)); | 409 callback(new Directory(path)); |
410 } else if (_onError != null) { | 410 } else if (_onError != null) { |
411 _onError("Cannot get directory for: ${_name}"); | 411 _onError("Cannot get directory for: ${_name}"); |
412 } | 412 } |
413 }); | 413 }); |
414 } | 414 } |
415 | 415 |
416 Directory directorySync() { | 416 Directory directorySync() { |
417 if (_asyncUsed) { | 417 if (_asyncUsed) { |
(...skipping 15 matching lines...) Expand all Loading... |
433 if (_onError != null) { | 433 if (_onError != null) { |
434 _onError("Unknown file mode. Use FileMode.READ, FileMode.WRITE " + | 434 _onError("Unknown file mode. Use FileMode.READ, FileMode.WRITE " + |
435 "or FileMode.APPEND."); | 435 "or FileMode.APPEND."); |
436 return; | 436 return; |
437 } | 437 } |
438 } | 438 } |
439 List request = new List(3); | 439 List request = new List(3); |
440 request[0] = _FileUtils.kOpenRequest; | 440 request[0] = _FileUtils.kOpenRequest; |
441 request[1] = _name; | 441 request[1] = _name; |
442 request[2] = mode._mode; // Direct int value for serialization. | 442 request[2] = mode._mode; // Direct int value for serialization. |
443 _fileService.call(request).receive((id, replyTo) { | 443 _fileService.call(request).then((id) { |
444 if (id != 0) { | 444 if (id != 0) { |
445 callback(new _RandomAccessFile(id, _name)); | 445 callback(new _RandomAccessFile(id, _name)); |
446 } else if (_onError != null) { | 446 } else if (_onError != null) { |
447 _onError("Cannot open file: $_name"); | 447 _onError("Cannot open file: $_name"); |
448 } | 448 } |
449 }); | 449 }); |
450 } | 450 } |
451 | 451 |
452 RandomAccessFile openSync([FileMode mode = FileMode.READ]) { | 452 RandomAccessFile openSync([FileMode mode = FileMode.READ]) { |
453 if (_asyncUsed) { | 453 if (_asyncUsed) { |
(...skipping 20 matching lines...) Expand all Loading... |
474 } | 474 } |
475 return new _RandomAccessFile(id, ""); | 475 return new _RandomAccessFile(id, ""); |
476 } | 476 } |
477 | 477 |
478 void fullPath(void callback(String result)) { | 478 void fullPath(void callback(String result)) { |
479 _ensureFileService(); | 479 _ensureFileService(); |
480 _asyncUsed = true; | 480 _asyncUsed = true; |
481 List request = new List(2); | 481 List request = new List(2); |
482 request[0] = _FileUtils.kFullPathRequest; | 482 request[0] = _FileUtils.kFullPathRequest; |
483 request[1] = _name; | 483 request[1] = _name; |
484 _fileService.call(request).receive((result, replyTo) { | 484 _fileService.call(request).then((result) { |
485 if (result != null) { | 485 if (result != null) { |
486 callback(result); | 486 callback(result); |
487 } else if (_onError != null) { | 487 } else if (_onError != null) { |
488 _onError("fullPath failed"); | 488 _onError("fullPath failed"); |
489 } | 489 } |
490 }); | 490 }); |
491 } | 491 } |
492 | 492 |
493 String fullPathSync() { | 493 String fullPathSync() { |
494 if (_asyncUsed) { | 494 if (_asyncUsed) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 void close(void callback()) { | 646 void close(void callback()) { |
647 if (_id == 0) return; | 647 if (_id == 0) return; |
648 _ensureFileService(); | 648 _ensureFileService(); |
649 _asyncUsed = true; | 649 _asyncUsed = true; |
650 List request = new List(2); | 650 List request = new List(2); |
651 request[0] = _FileUtils.kCloseRequest; | 651 request[0] = _FileUtils.kCloseRequest; |
652 request[1] = _id; | 652 request[1] = _id; |
653 // Set the id_ to 0 (NULL) to ensure the no more async requests | 653 // Set the id_ to 0 (NULL) to ensure the no more async requests |
654 // can be issues for this file. | 654 // can be issues for this file. |
655 _id = 0; | 655 _id = 0; |
656 _fileService.call(request).receive((result, replyTo) { | 656 _fileService.call(request).then((result) { |
657 if (result != -1) { | 657 if (result != -1) { |
658 _id = result; | 658 _id = result; |
659 callback(); | 659 callback(); |
660 } else if (_onError != null) { | 660 } else if (_onError != null) { |
661 _onError("Cannot close file: $_name"); | 661 _onError("Cannot close file: $_name"); |
662 } | 662 } |
663 }); | 663 }); |
664 } | 664 } |
665 | 665 |
666 void closeSync() { | 666 void closeSync() { |
667 if (_asyncUsed) { | 667 if (_asyncUsed) { |
668 throw new FileIOException( | 668 throw new FileIOException( |
669 "Mixed use of synchronous and asynchronous API"); | 669 "Mixed use of synchronous and asynchronous API"); |
670 } | 670 } |
671 var id = _FileUtils.close(_id); | 671 var id = _FileUtils.close(_id); |
672 if (id == -1) { | 672 if (id == -1) { |
673 throw new FileIOException("Cannot close file: $_name"); | 673 throw new FileIOException("Cannot close file: $_name"); |
674 } | 674 } |
675 _id = id; | 675 _id = id; |
676 } | 676 } |
677 | 677 |
678 void readByte(void callback(int byte)) { | 678 void readByte(void callback(int byte)) { |
679 _ensureFileService(); | 679 _ensureFileService(); |
680 _asyncUsed = true; | 680 _asyncUsed = true; |
681 List request = new List(2); | 681 List request = new List(2); |
682 request[0] = _FileUtils.kReadByteRequest; | 682 request[0] = _FileUtils.kReadByteRequest; |
683 request[1] = _id; | 683 request[1] = _id; |
684 _fileService.call(request).receive((result, replyTo) { | 684 _fileService.call(request).then((result) { |
685 if (result != -1) { | 685 if (result != -1) { |
686 callback(result); | 686 callback(result); |
687 } else if (_onError != null) { | 687 } else if (_onError != null) { |
688 _onError("readByte failed"); | 688 _onError("readByte failed"); |
689 } | 689 } |
690 }); | 690 }); |
691 } | 691 } |
692 | 692 |
693 int readByteSync() { | 693 int readByteSync() { |
694 if (_asyncUsed) { | 694 if (_asyncUsed) { |
(...skipping 14 matching lines...) Expand all Loading... |
709 if (buffer is !List || offset is !int || bytes is !int) { | 709 if (buffer is !List || offset is !int || bytes is !int) { |
710 if (_onError != null) { | 710 if (_onError != null) { |
711 _onError("Invalid arguments to readList"); | 711 _onError("Invalid arguments to readList"); |
712 } | 712 } |
713 return; | 713 return; |
714 }; | 714 }; |
715 List request = new List(3); | 715 List request = new List(3); |
716 request[0] = _FileUtils.kReadListRequest; | 716 request[0] = _FileUtils.kReadListRequest; |
717 request[1] = _id; | 717 request[1] = _id; |
718 request[2] = bytes; | 718 request[2] = bytes; |
719 _fileService.call(request).receive((result, replyTo) { | 719 _fileService.call(request).then((result) { |
720 if (result is List && result.length == 2 && result[0] != -1) { | 720 if (result is List && result.length == 2 && result[0] != -1) { |
721 var read = result[0]; | 721 var read = result[0]; |
722 var data = result[1]; | 722 var data = result[1]; |
723 buffer.setRange(offset, read, data); | 723 buffer.setRange(offset, read, data); |
724 callback(read); | 724 callback(read); |
725 return; | 725 return; |
726 } else if (_onError != null) { | 726 } else if (_onError != null) { |
727 _onError(result is String ? result : "readList failed"); | 727 _onError(result is String ? result : "readList failed"); |
728 } | 728 } |
729 }); | 729 }); |
(...skipping 27 matching lines...) Expand all Loading... |
757 if (_onError != null) { | 757 if (_onError != null) { |
758 _onError("Invalid argument to writeByte"); | 758 _onError("Invalid argument to writeByte"); |
759 } | 759 } |
760 return; | 760 return; |
761 } | 761 } |
762 List request = new List(3); | 762 List request = new List(3); |
763 request[0] = _FileUtils.kWriteByteRequest; | 763 request[0] = _FileUtils.kWriteByteRequest; |
764 request[1] = _id; | 764 request[1] = _id; |
765 request[2] = value; | 765 request[2] = value; |
766 _writeEnqueued(); | 766 _writeEnqueued(); |
767 _fileService.call(request).receive((result, replyTo) { | 767 _fileService.call(request).then((result) { |
768 _writeCompleted(); | 768 _writeCompleted(); |
769 if (result == -1 && _onError !== null) { | 769 if (result == -1 && _onError !== null) { |
770 _onError("writeByte failed"); | 770 _onError("writeByte failed"); |
771 } | 771 } |
772 }); | 772 }); |
773 } | 773 } |
774 | 774 |
775 int writeByteSync(int value) { | 775 int writeByteSync(int value) { |
776 if (_asyncUsed) { | 776 if (_asyncUsed) { |
777 throw new FileIOException( | 777 throw new FileIOException( |
(...skipping 24 matching lines...) Expand all Loading... |
802 List outBuffer = result[0]; | 802 List outBuffer = result[0]; |
803 int outOffset = result[1]; | 803 int outOffset = result[1]; |
804 | 804 |
805 List request = new List(5); | 805 List request = new List(5); |
806 request[0] = _FileUtils.kWriteListRequest; | 806 request[0] = _FileUtils.kWriteListRequest; |
807 request[1] = _id; | 807 request[1] = _id; |
808 request[2] = outBuffer; | 808 request[2] = outBuffer; |
809 request[3] = outOffset; | 809 request[3] = outOffset; |
810 request[4] = bytes; | 810 request[4] = bytes; |
811 _writeEnqueued(); | 811 _writeEnqueued(); |
812 _fileService.call(request).receive((result, replyTo) { | 812 _fileService.call(request).then((result) { |
813 _writeCompleted(); | 813 _writeCompleted(); |
814 if (result == -1 && _onError !== null) { | 814 if (result == -1 && _onError !== null) { |
815 _onError("writeList failed"); | 815 _onError("writeList failed"); |
816 } | 816 } |
817 }); | 817 }); |
818 } | 818 } |
819 | 819 |
820 int writeListSync(List<int> buffer, int offset, int bytes) { | 820 int writeListSync(List<int> buffer, int offset, int bytes) { |
821 if (_asyncUsed) { | 821 if (_asyncUsed) { |
822 throw new FileIOException( | 822 throw new FileIOException( |
(...skipping 16 matching lines...) Expand all Loading... |
839 } | 839 } |
840 | 840 |
841 void writeString(String string, [Encoding encoding = Encoding.UTF_8]) { | 841 void writeString(String string, [Encoding encoding = Encoding.UTF_8]) { |
842 _ensureFileService(); | 842 _ensureFileService(); |
843 _asyncUsed = true; | 843 _asyncUsed = true; |
844 List request = new List(3); | 844 List request = new List(3); |
845 request[0] = _FileUtils.kWriteStringRequest; | 845 request[0] = _FileUtils.kWriteStringRequest; |
846 request[1] = _id; | 846 request[1] = _id; |
847 request[2] = string; | 847 request[2] = string; |
848 _writeEnqueued(); | 848 _writeEnqueued(); |
849 _fileService.call(request).receive((result, replyTo) { | 849 _fileService.call(request).then((result) { |
850 _writeCompleted(); | 850 _writeCompleted(); |
851 if (result == -1 && _onError !== null) { | 851 if (result == -1 && _onError !== null) { |
852 _onError("writeString failed"); | 852 _onError("writeString failed"); |
853 } | 853 } |
854 }); | 854 }); |
855 } | 855 } |
856 | 856 |
857 int writeStringSync(String string, [Encoding encoding = Encoding.UTF_8]) { | 857 int writeStringSync(String string, [Encoding encoding = Encoding.UTF_8]) { |
858 if (_asyncUsed) { | 858 if (_asyncUsed) { |
859 throw new FileIOException( | 859 throw new FileIOException( |
860 "Mixed use of synchronous and asynchronous API"); | 860 "Mixed use of synchronous and asynchronous API"); |
861 } | 861 } |
862 int result = _FileUtils.checkedWriteString(_id, string); | 862 int result = _FileUtils.checkedWriteString(_id, string); |
863 if (result == -1) { | 863 if (result == -1) { |
864 throw new FileIOException("writeString failed"); | 864 throw new FileIOException("writeString failed"); |
865 } | 865 } |
866 return result; | 866 return result; |
867 } | 867 } |
868 | 868 |
869 void position(void callback(int position)) { | 869 void position(void callback(int position)) { |
870 _ensureFileService(); | 870 _ensureFileService(); |
871 _asyncUsed = true; | 871 _asyncUsed = true; |
872 List request = new List(2); | 872 List request = new List(2); |
873 request[0] = _FileUtils.kPositionRequest; | 873 request[0] = _FileUtils.kPositionRequest; |
874 request[1] = _id; | 874 request[1] = _id; |
875 _fileService.call(request).receive((result, replyTo) { | 875 _fileService.call(request).then((result) { |
876 if (result != -1) { | 876 if (result != -1) { |
877 callback(result); | 877 callback(result); |
878 } else if (_onError != null) { | 878 } else if (_onError != null) { |
879 _onError("position failed"); | 879 _onError("position failed"); |
880 } | 880 } |
881 }); | 881 }); |
882 } | 882 } |
883 | 883 |
884 int positionSync() { | 884 int positionSync() { |
885 if (_asyncUsed) { | 885 if (_asyncUsed) { |
886 throw new FileIOException( | 886 throw new FileIOException( |
887 "Mixed use of synchronous and asynchronous API"); | 887 "Mixed use of synchronous and asynchronous API"); |
888 } | 888 } |
889 int result = _FileUtils.position(_id); | 889 int result = _FileUtils.position(_id); |
890 if (result == -1) { | 890 if (result == -1) { |
891 throw new FileIOException("position failed"); | 891 throw new FileIOException("position failed"); |
892 } | 892 } |
893 return result; | 893 return result; |
894 } | 894 } |
895 | 895 |
896 void setPosition(int position, void callback()) { | 896 void setPosition(int position, void callback()) { |
897 _ensureFileService(); | 897 _ensureFileService(); |
898 _asyncUsed = true; | 898 _asyncUsed = true; |
899 List request = new List(3); | 899 List request = new List(3); |
900 request[0] = _FileUtils.kSetPositionRequest; | 900 request[0] = _FileUtils.kSetPositionRequest; |
901 request[1] = _id; | 901 request[1] = _id; |
902 request[2] = position; | 902 request[2] = position; |
903 _fileService.call(request).receive((result, replyTo) { | 903 _fileService.call(request).then((result) { |
904 if (result) { | 904 if (result) { |
905 callback(); | 905 callback(); |
906 } else if (_onError != null) { | 906 } else if (_onError != null) { |
907 _onError("setPosition failed"); | 907 _onError("setPosition failed"); |
908 } | 908 } |
909 }); | 909 }); |
910 } | 910 } |
911 | 911 |
912 void setPositionSync(int position) { | 912 void setPositionSync(int position) { |
913 _ensureFileService(); | 913 _ensureFileService(); |
914 if (_asyncUsed) { | 914 if (_asyncUsed) { |
915 throw new FileIOException( | 915 throw new FileIOException( |
916 "Mixed use of synchronous and asynchronous API"); | 916 "Mixed use of synchronous and asynchronous API"); |
917 } | 917 } |
918 bool result = _FileUtils.setPosition(_id, position); | 918 bool result = _FileUtils.setPosition(_id, position); |
919 if (result == false) { | 919 if (result == false) { |
920 throw new FileIOException("setPosition failed"); | 920 throw new FileIOException("setPosition failed"); |
921 } | 921 } |
922 } | 922 } |
923 | 923 |
924 void truncate(int length, void callback()) { | 924 void truncate(int length, void callback()) { |
925 _ensureFileService(); | 925 _ensureFileService(); |
926 _asyncUsed = true; | 926 _asyncUsed = true; |
927 List request = new List(3); | 927 List request = new List(3); |
928 request[0] = _FileUtils.kTruncateRequest; | 928 request[0] = _FileUtils.kTruncateRequest; |
929 request[1] = _id; | 929 request[1] = _id; |
930 request[2] = length; | 930 request[2] = length; |
931 _fileService.call(request).receive((result, replyTo) { | 931 _fileService.call(request).then((result) { |
932 if (result) { | 932 if (result) { |
933 callback(); | 933 callback(); |
934 } else if (_onError != null) { | 934 } else if (_onError != null) { |
935 _onError("truncate failed"); | 935 _onError("truncate failed"); |
936 } | 936 } |
937 }); | 937 }); |
938 } | 938 } |
939 | 939 |
940 void truncateSync(int length) { | 940 void truncateSync(int length) { |
941 if (_asyncUsed) { | 941 if (_asyncUsed) { |
942 throw new FileIOException( | 942 throw new FileIOException( |
943 "Mixed use of synchronous and asynchronous API"); | 943 "Mixed use of synchronous and asynchronous API"); |
944 } | 944 } |
945 bool result = _FileUtils.truncate(_id, length); | 945 bool result = _FileUtils.truncate(_id, length); |
946 if (result == false) { | 946 if (result == false) { |
947 throw new FileIOException("truncate failed"); | 947 throw new FileIOException("truncate failed"); |
948 } | 948 } |
949 } | 949 } |
950 | 950 |
951 void length(void callback(int length)) { | 951 void length(void callback(int length)) { |
952 _ensureFileService(); | 952 _ensureFileService(); |
953 _asyncUsed = true; | 953 _asyncUsed = true; |
954 List request = new List(2); | 954 List request = new List(2); |
955 request[0] = _FileUtils.kLengthRequest; | 955 request[0] = _FileUtils.kLengthRequest; |
956 request[1] = _id; | 956 request[1] = _id; |
957 _fileService.call(request).receive((result, replyTo) { | 957 _fileService.call(request).then((result) { |
958 if (result != -1) { | 958 if (result != -1) { |
959 callback(result); | 959 callback(result); |
960 } else if (_onError != null) { | 960 } else if (_onError != null) { |
961 _onError("length failed"); | 961 _onError("length failed"); |
962 } | 962 } |
963 }); | 963 }); |
964 } | 964 } |
965 | 965 |
966 int lengthSync() { | 966 int lengthSync() { |
967 if (_asyncUsed) { | 967 if (_asyncUsed) { |
968 throw new FileIOException( | 968 throw new FileIOException( |
969 "Mixed use of synchronous and asynchronous API"); | 969 "Mixed use of synchronous and asynchronous API"); |
970 } | 970 } |
971 int result = _FileUtils.length(_id); | 971 int result = _FileUtils.length(_id); |
972 if (result == -1) { | 972 if (result == -1) { |
973 throw new FileIOException("length failed"); | 973 throw new FileIOException("length failed"); |
974 } | 974 } |
975 return result; | 975 return result; |
976 } | 976 } |
977 | 977 |
978 void flush(void callback()) { | 978 void flush(void callback()) { |
979 _ensureFileService(); | 979 _ensureFileService(); |
980 _asyncUsed = true; | 980 _asyncUsed = true; |
981 List request = new List(2); | 981 List request = new List(2); |
982 request[0] = _FileUtils.kFlushRequest; | 982 request[0] = _FileUtils.kFlushRequest; |
983 request[1] = _id; | 983 request[1] = _id; |
984 _fileService.call(request).receive((result, replyTo) { | 984 _fileService.call(request).then((result) { |
985 if (result != -1) { | 985 if (result != -1) { |
986 callback(); | 986 callback(); |
987 } else if (_onError != null) { | 987 } else if (_onError != null) { |
988 _onError("flush failed"); | 988 _onError("flush failed"); |
989 } | 989 } |
990 }); | 990 }); |
991 } | 991 } |
992 | 992 |
993 void flushSync() { | 993 void flushSync() { |
994 if (_asyncUsed) { | 994 if (_asyncUsed) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 bool _asyncUsed; | 1043 bool _asyncUsed; |
1044 int _pendingWrites = 0; | 1044 int _pendingWrites = 0; |
1045 | 1045 |
1046 SendPort _fileService; | 1046 SendPort _fileService; |
1047 | 1047 |
1048 Timer _noPendingWriteTimer; | 1048 Timer _noPendingWriteTimer; |
1049 | 1049 |
1050 Function _onNoPendingWrites; | 1050 Function _onNoPendingWrites; |
1051 Function _onError; | 1051 Function _onError; |
1052 } | 1052 } |
OLD | NEW |