| Index: runtime/bin/file_impl.dart
|
| diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
|
| index 3ee2765d1d5791ddf10b437eaec0462aec5d80b3..d050772aa7b599097250a4ae60eedef88061fcc5 100644
|
| --- a/runtime/bin/file_impl.dart
|
| +++ b/runtime/bin/file_impl.dart
|
| @@ -400,14 +400,6 @@ class _FileBase {
|
| _onError = handler;
|
| }
|
|
|
| - _checkNotAsync() {
|
| - if (_asyncUsed) {
|
| - throw new FileIOException(
|
| - "Mixed use of synchronous and asynchronous API");
|
| - }
|
| - }
|
| -
|
| - bool _asyncUsed = false;
|
| Function _onError;
|
| }
|
|
|
| @@ -418,7 +410,6 @@ class _File extends _FileBase implements File {
|
|
|
| void exists(void callback(bool exists)) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(2);
|
| request[0] = _FileUtils.kExistsRequest;
|
| request[1] = _name;
|
| @@ -432,13 +423,11 @@ class _File extends _FileBase implements File {
|
| }
|
|
|
| bool existsSync() {
|
| - _checkNotAsync();
|
| return _FileUtils.checkedExists(_name);
|
| }
|
|
|
| void create(void callback()) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(2);
|
| request[0] = _FileUtils.kCreateRequest;
|
| request[1] = _name;
|
| @@ -452,7 +441,6 @@ class _File extends _FileBase implements File {
|
| }
|
|
|
| void createSync() {
|
| - _checkNotAsync();
|
| bool created = _FileUtils.checkedCreate(_name);
|
| if (!created) {
|
| throw new FileIOException("Cannot create file: $_name");
|
| @@ -461,7 +449,6 @@ class _File extends _FileBase implements File {
|
|
|
| void delete(void callback()) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(2);
|
| request[0] = _FileUtils.kDeleteRequest;
|
| request[1] = _name;
|
| @@ -475,13 +462,11 @@ class _File extends _FileBase implements File {
|
| }
|
|
|
| void deleteSync() {
|
| - _checkNotAsync();
|
| _FileUtils.checkedDelete(_name);
|
| }
|
|
|
| void directory(void callback(Directory dir)) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(2);
|
| request[0] = _FileUtils.kDirectoryRequest;
|
| request[1] = _name;
|
| @@ -495,14 +480,12 @@ class _File extends _FileBase implements File {
|
| }
|
|
|
| Directory directorySync() {
|
| - _checkNotAsync();
|
| _FileUtils.checkedDirectory(_name);
|
| return new Directory(_FileUtils.directory(_name));
|
| }
|
|
|
| void open(FileMode mode, void callback(RandomAccessFile file)) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| if (mode != FileMode.READ &&
|
| mode != FileMode.WRITE &&
|
| mode != FileMode.APPEND) {
|
| @@ -525,7 +508,6 @@ class _File extends _FileBase implements File {
|
| }
|
|
|
| RandomAccessFile openSync([FileMode mode = FileMode.READ]) {
|
| - _checkNotAsync();
|
| if (mode != FileMode.READ &&
|
| mode != FileMode.WRITE &&
|
| mode != FileMode.APPEND) {
|
| @@ -547,7 +529,6 @@ class _File extends _FileBase implements File {
|
|
|
| void fullPath(void callback(String result)) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(2);
|
| request[0] = _FileUtils.kFullPathRequest;
|
| request[1] = _name;
|
| @@ -561,7 +542,6 @@ class _File extends _FileBase implements File {
|
| }
|
|
|
| String fullPathSync() {
|
| - _checkNotAsync();
|
| return _FileUtils.checkedFullPath(_name);
|
| }
|
|
|
| @@ -580,7 +560,6 @@ class _File extends _FileBase implements File {
|
|
|
| void readAsBytes(void callback(List<int> bytes)) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| var chunks = new _BufferList();
|
| var stream = openInputStream();
|
| stream.onClosed = () {
|
| @@ -598,7 +577,6 @@ class _File extends _FileBase implements File {
|
| }
|
|
|
| List<int> readAsBytesSync() {
|
| - _checkNotAsync();
|
| var opened = openSync();
|
| var length = opened.lengthSync();
|
| var result = new ByteArray(length);
|
| @@ -612,7 +590,6 @@ class _File extends _FileBase implements File {
|
|
|
| void readAsText(Encoding encoding, void callback(String text)) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| var decoder = _StringDecoders.decoder(encoding);
|
| readAsBytes((bytes) {
|
| try {
|
| @@ -628,7 +605,6 @@ class _File extends _FileBase implements File {
|
| }
|
|
|
| String readAsTextSync([Encoding encoding = Encoding.UTF_8]) {
|
| - _checkNotAsync();
|
| var decoder = _StringDecoders.decoder(encoding);
|
| List<int> bytes = readAsBytesSync();
|
| decoder.write(bytes);
|
| @@ -653,7 +629,6 @@ class _File extends _FileBase implements File {
|
|
|
| void readAsLines(Encoding encoding, void callback(List<String> lines)) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| var decoder = _StringDecoders.decoder(encoding);
|
| readAsBytes((bytes) {
|
| try {
|
| @@ -669,7 +644,6 @@ class _File extends _FileBase implements File {
|
| }
|
|
|
| List<String> readAsLinesSync([Encoding encoding = Encoding.UTF_8]) {
|
| - _checkNotAsync();
|
| var decoder = _StringDecoders.decoder(encoding);
|
| List<int> bytes = readAsBytesSync();
|
| decoder.write(bytes);
|
| @@ -696,7 +670,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| void close(void callback()) {
|
| if (_id == 0) return;
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(2);
|
| request[0] = _FileUtils.kCloseRequest;
|
| request[1] = _id;
|
| @@ -714,7 +687,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
|
|
| void closeSync() {
|
| - _checkNotAsync();
|
| var id = _FileUtils.close(_id);
|
| if (id == -1) {
|
| throw new FileIOException("Cannot close file: $_name");
|
| @@ -724,7 +696,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
|
|
| void readByte(void callback(int byte)) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(2);
|
| request[0] = _FileUtils.kReadByteRequest;
|
| request[1] = _id;
|
| @@ -738,7 +709,7 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
|
|
| int readByteSync() {
|
| - _checkNotAsyncAndNotClosed();
|
| + _checkNotClosed();
|
| var result = _FileUtils.readByte(_id);
|
| if (result is OSError) {
|
| throw new FileIOException("readByte failed", result);
|
| @@ -749,7 +720,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| void readList(List<int> buffer, int offset, int bytes,
|
| void callback(int read)) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| if (buffer is !List || offset is !int || bytes is !int) {
|
| if (_onError != null) {
|
| _onError("Invalid arguments to readList");
|
| @@ -773,7 +743,7 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
|
|
| int readListSync(List<int> buffer, int offset, int bytes) {
|
| - _checkNotAsyncAndNotClosed();
|
| + _checkNotClosed();
|
| if (buffer is !List || offset is !int || bytes is !int) {
|
| throw new FileIOException("Invalid arguments to readList");
|
| }
|
| @@ -792,7 +762,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
|
|
| void writeByte(int value) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| if (value is !int) {
|
| if (_onError != null) {
|
| _onError("Invalid argument to writeByte");
|
| @@ -813,7 +782,7 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
|
|
| int writeByteSync(int value) {
|
| - _checkNotAsyncAndNotClosed();
|
| + _checkNotClosed();
|
| if (value is !int) {
|
| throw new FileIOException("Invalid argument to writeByte");
|
| }
|
| @@ -826,7 +795,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
|
|
| void writeList(List<int> buffer, int offset, int bytes) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| if (buffer is !List || offset is !int || bytes is !int) {
|
| if (_onError != null) {
|
| _onError("Invalid arguments to writeList");
|
| @@ -855,7 +823,7 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
|
|
| int writeListSync(List<int> buffer, int offset, int bytes) {
|
| - _checkNotAsyncAndNotClosed();
|
| + _checkNotClosed();
|
| if (buffer is !List || offset is !int || bytes is !int) {
|
| throw new FileIOException("Invalid arguments to writeList");
|
| }
|
| @@ -874,7 +842,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
|
|
| void writeString(String string, [Encoding encoding = Encoding.UTF_8]) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(3);
|
| request[0] = _FileUtils.kWriteStringRequest;
|
| request[1] = _id;
|
| @@ -889,7 +856,7 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
|
|
| int writeStringSync(String string, [Encoding encoding = Encoding.UTF_8]) {
|
| - _checkNotAsyncAndNotClosed();
|
| + _checkNotClosed();
|
| var result = _FileUtils.checkedWriteString(_id, string);
|
| if (result is OSError) {
|
| throw new FileIOException("writeString failed", result);
|
| @@ -899,7 +866,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
|
|
| void position(void callback(int position)) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(2);
|
| request[0] = _FileUtils.kPositionRequest;
|
| request[1] = _id;
|
| @@ -913,7 +879,7 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
|
|
| int positionSync() {
|
| - _checkNotAsyncAndNotClosed();
|
| + _checkNotClosed();
|
| var result = _FileUtils.position(_id);
|
| if (result is OSError) {
|
| throw new FileIOException("position failed", result);
|
| @@ -923,7 +889,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
|
|
| void setPosition(int position, void callback()) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(3);
|
| request[0] = _FileUtils.kSetPositionRequest;
|
| request[1] = _id;
|
| @@ -938,7 +903,7 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
|
|
| void setPositionSync(int position) {
|
| - _checkNotAsyncAndNotClosed();
|
| + _checkNotClosed();
|
| var result = _FileUtils.setPosition(_id, position);
|
| if (result is OSError) {
|
| throw new FileIOException("setPosition failed", result);
|
| @@ -947,7 +912,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
|
|
| void truncate(int length, void callback()) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(3);
|
| request[0] = _FileUtils.kTruncateRequest;
|
| request[1] = _id;
|
| @@ -962,7 +926,7 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
|
|
| void truncateSync(int length) {
|
| - _checkNotAsyncAndNotClosed();
|
| + _checkNotClosed();
|
| var result = _FileUtils.truncate(_id, length);
|
| if (result is OSError) {
|
| throw new FileIOException("truncate failed", result);
|
| @@ -971,7 +935,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
|
|
| void length(void callback(int length)) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(2);
|
| request[0] = _FileUtils.kLengthRequest;
|
| request[1] = _id;
|
| @@ -985,7 +948,7 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
|
|
| int lengthSync() {
|
| - _checkNotAsyncAndNotClosed();
|
| + _checkNotClosed();
|
| var result = _FileUtils.length(_id);
|
| if (result is OSError) {
|
| throw new FileIOException("length failed", result);
|
| @@ -995,7 +958,6 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
|
|
| void flush(void callback()) {
|
| _ensureFileService();
|
| - _asyncUsed = true;
|
| List request = new List(2);
|
| request[0] = _FileUtils.kFlushRequest;
|
| request[1] = _id;
|
| @@ -1009,7 +971,7 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
|
|
| void flushSync() {
|
| - _checkNotAsyncAndNotClosed();
|
| + _checkNotClosed();
|
| var result = _FileUtils.flush(_id);
|
| if (result is OSError) {
|
| throw new FileIOException("flush failed", result);
|
| @@ -1048,8 +1010,7 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
|
| }
|
| }
|
|
|
| - _checkNotAsyncAndNotClosed() {
|
| - _checkNotAsync();
|
| + void _checkNotClosed() {
|
| if (_id == 0) {
|
| throw new FileIOException("File closed");
|
| }
|
|
|