| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 Future<File> close() { | 196 Future<File> close() { |
| 197 return _openFuture.then((openedFile) => openedFile.close()); | 197 return _openFuture.then((openedFile) => openedFile.close()); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 | 201 |
| 202 const int _EXISTS_REQUEST = 0; | 202 const int _EXISTS_REQUEST = 0; |
| 203 const int _CREATE_REQUEST = 1; | 203 const int _CREATE_REQUEST = 1; |
| 204 const int _DELETE_REQUEST = 2; | 204 const int _DELETE_REQUEST = 2; |
| 205 const int _OPEN_REQUEST = 3; | 205 const int _RENAME_REQUEST = 3; |
| 206 const int _FULL_PATH_REQUEST = 4; | 206 const int _OPEN_REQUEST = 4; |
| 207 const int _CLOSE_REQUEST = 5; | 207 const int _FULL_PATH_REQUEST = 5; |
| 208 const int _POSITION_REQUEST = 6; | 208 const int _CLOSE_REQUEST = 6; |
| 209 const int _SET_POSITION_REQUEST = 7; | 209 const int _POSITION_REQUEST = 7; |
| 210 const int _TRUNCATE_REQUEST = 8; | 210 const int _SET_POSITION_REQUEST = 8; |
| 211 const int _LENGTH_REQUEST = 9; | 211 const int _TRUNCATE_REQUEST = 9; |
| 212 const int _LENGTH_FROM_PATH_REQUEST = 10; | 212 const int _LENGTH_REQUEST = 10; |
| 213 const int _LAST_MODIFIED_REQUEST = 11; | 213 const int _LENGTH_FROM_PATH_REQUEST = 11; |
| 214 const int _FLUSH_REQUEST = 12; | 214 const int _LAST_MODIFIED_REQUEST = 12; |
| 215 const int _READ_BYTE_REQUEST = 13; | 215 const int _FLUSH_REQUEST = 13; |
| 216 const int _WRITE_BYTE_REQUEST = 14; | 216 const int _READ_BYTE_REQUEST = 14; |
| 217 const int _READ_REQUEST = 15; | 217 const int _WRITE_BYTE_REQUEST = 15; |
| 218 const int _READ_LIST_REQUEST = 16; | 218 const int _READ_REQUEST = 16; |
| 219 const int _WRITE_LIST_REQUEST = 17; | 219 const int _READ_LIST_REQUEST = 17; |
| 220 const int _CREATE_LINK_REQUEST = 18; | 220 const int _WRITE_LIST_REQUEST = 18; |
| 221 const int _DELETE_LINK_REQUEST = 19; | 221 const int _CREATE_LINK_REQUEST = 19; |
| 222 const int _LINK_TARGET_REQUEST = 20; | 222 const int _DELETE_LINK_REQUEST = 20; |
| 223 const int _TYPE_REQUEST = 21; | 223 const int _LINK_TARGET_REQUEST = 21; |
| 224 const int _IDENTICAL_REQUEST = 22; | 224 const int _TYPE_REQUEST = 22; |
| 225 const int _STAT_REQUEST = 23; | 225 const int _IDENTICAL_REQUEST = 23; |
| 226 const int _STAT_REQUEST = 24; |
| 226 | 227 |
| 227 // TODO(ager): The only reason for this class is that the patching | 228 // TODO(ager): The only reason for this class is that the patching |
| 228 // mechanism doesn't seem to like patching a private top level | 229 // mechanism doesn't seem to like patching a private top level |
| 229 // function. | 230 // function. |
| 230 class _FileUtils { | 231 class _FileUtils { |
| 231 external static SendPort _newServicePort(); | 232 external static SendPort _newServicePort(); |
| 232 } | 233 } |
| 233 | 234 |
| 234 // Class for encapsulating the native implementation of files. | 235 // Class for encapsulating the native implementation of files. |
| 235 class _File implements File { | 236 class _File implements File { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 310 |
| 310 external static _delete(String path); | 311 external static _delete(String path); |
| 311 | 312 |
| 312 external static _deleteLink(String path); | 313 external static _deleteLink(String path); |
| 313 | 314 |
| 314 void deleteSync() { | 315 void deleteSync() { |
| 315 var result = _delete(_path); | 316 var result = _delete(_path); |
| 316 throwIfError(result, "Cannot delete file '$_path'"); | 317 throwIfError(result, "Cannot delete file '$_path'"); |
| 317 } | 318 } |
| 318 | 319 |
| 320 Future<File> rename(String newPath) { |
| 321 _ensureFileService(); |
| 322 List request = new List(3); |
| 323 request[0] = _RENAME_REQUEST; |
| 324 request[1] = _path; |
| 325 request[2] = newPath; |
| 326 return _fileService.call(request).then((response) { |
| 327 if (_isErrorResponse(response)) { |
| 328 throw _exceptionFromResponse( |
| 329 response, "Cannot rename file '$_path' to '$newPath'"); |
| 330 } |
| 331 return new File(newPath); |
| 332 }); |
| 333 } |
| 334 |
| 335 external static _rename(String oldPath, String newPath); |
| 336 |
| 337 File renameSync(String newPath) { |
| 338 var result = _rename(_path, newPath); |
| 339 throwIfError(result, "Cannot rename file '$_path' to '$newPath'"); |
| 340 return new File(newPath); |
| 341 } |
| 342 |
| 319 Directory get directory { | 343 Directory get directory { |
| 320 Path path = new Path(_path).directoryPath; | 344 Path path = new Path(_path).directoryPath; |
| 321 return new Directory.fromPath(path); | 345 return new Directory.fromPath(path); |
| 322 } | 346 } |
| 323 | 347 |
| 324 Future<RandomAccessFile> open({FileMode mode: FileMode.READ}) { | 348 Future<RandomAccessFile> open({FileMode mode: FileMode.READ}) { |
| 325 _ensureFileService(); | 349 _ensureFileService(); |
| 326 if (mode != FileMode.READ && | 350 if (mode != FileMode.READ && |
| 327 mode != FileMode.WRITE && | 351 mode != FileMode.WRITE && |
| 328 mode != FileMode.APPEND) { | 352 mode != FileMode.APPEND) { |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 | 1005 |
| 982 Future _closedException() { | 1006 Future _closedException() { |
| 983 return new Future.error(new FileException("File closed '$_path'")); | 1007 return new Future.error(new FileException("File closed '$_path'")); |
| 984 } | 1008 } |
| 985 | 1009 |
| 986 final String _path; | 1010 final String _path; |
| 987 int _id; | 1011 int _id; |
| 988 | 1012 |
| 989 SendPort _fileService; | 1013 SendPort _fileService; |
| 990 } | 1014 } |
| OLD | NEW |