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

Side by Side Diff: sdk/lib/io/file_impl.dart

Issue 105133004: Add File.copy(Sync) to dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix permissions. Created 7 years 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 | « sdk/lib/io/file.dart ('k') | sdk/lib/io/io_service.dart » ('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) 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 external static _rename(String oldPath, String newPath); 320 external static _rename(String oldPath, String newPath);
321 321
322 external static _renameLink(String oldPath, String newPath); 322 external static _renameLink(String oldPath, String newPath);
323 323
324 File renameSync(String newPath) { 324 File renameSync(String newPath) {
325 var result = _rename(path, newPath); 325 var result = _rename(path, newPath);
326 throwIfError(result, "Cannot rename file to '$newPath'", path); 326 throwIfError(result, "Cannot rename file to '$newPath'", path);
327 return new File(newPath); 327 return new File(newPath);
328 } 328 }
329 329
330 Future<File> copy(String newPath) {
331 return _IOService.dispatch(_FILE_COPY, [path, newPath]).then((response) {
332 if (_isErrorResponse(response)) {
333 throw _exceptionFromResponse(
334 response, "Cannot copy file to '$newPath'", path);
335 }
336 return new File(newPath);
337 });
338 }
339
340 external static _copy(String oldPath, String newPath);
341
342 File copySync(String newPath) {
343 var result = _copy(path, newPath);
344 throwIfError(result, "Cannot copy file to '$newPath'", path);
345 return new File(newPath);
346 }
347
330 Future<RandomAccessFile> open({FileMode mode: FileMode.READ}) { 348 Future<RandomAccessFile> open({FileMode mode: FileMode.READ}) {
331 if (mode != FileMode.READ && 349 if (mode != FileMode.READ &&
332 mode != FileMode.WRITE && 350 mode != FileMode.WRITE &&
333 mode != FileMode.APPEND) { 351 mode != FileMode.APPEND) {
334 return new Future.error(new ArgumentError()); 352 return new Future.error(new ArgumentError());
335 } 353 }
336 return _IOService.dispatch(_FILE_OPEN, [path, mode._mode]).then((response) { 354 return _IOService.dispatch(_FILE_OPEN, [path, mode._mode]).then((response) {
337 if (_isErrorResponse(response)) { 355 if (_isErrorResponse(response)) {
338 throw _exceptionFromResponse(response, "Cannot open file", path); 356 throw _exceptionFromResponse(response, "Cannot open file", path);
339 } 357 }
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 908
891 void _checkAvailable() { 909 void _checkAvailable() {
892 if (_asyncDispatched) { 910 if (_asyncDispatched) {
893 throw new FileSystemException("An async operation is currently pending", p ath); 911 throw new FileSystemException("An async operation is currently pending", p ath);
894 } 912 }
895 if (closed) { 913 if (closed) {
896 throw new FileSystemException("File closed", path); 914 throw new FileSystemException("File closed", path);
897 } 915 }
898 } 916 }
899 } 917 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file.dart ('k') | sdk/lib/io/io_service.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698