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

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

Issue 2848703003: Fix a batch of DDC SDK compile errors. (Closed)
Patch Set: Created 3 years, 7 months 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
« no previous file with comments | « sdk/lib/core/string.dart ('k') | no next file » | 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 class _FileStream extends Stream<List<int>> { 10 class _FileStream extends Stream<List<int>> {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } catch (e, stackTrace) { 191 } catch (e, stackTrace) {
192 error(e, stackTrace); 192 error(e, stackTrace);
193 } 193 }
194 }, onDone: () { 194 }, onDone: () {
195 completer.complete(_file); 195 completer.complete(_file);
196 }, onError: error, cancelOnError: true); 196 }, onError: error, cancelOnError: true);
197 }).catchError(completer.completeError); 197 }).catchError(completer.completeError);
198 return completer.future; 198 return completer.future;
199 } 199 }
200 200
201 Future<File> close() => 201 Future close() => _openFuture.then((openedFile) => openedFile.close());
floitsch 2017/04/27 22:10:25 Please use my changes instead: https://codereview.
Bob Nystrom 2017/04/28 00:13:07 Done. (FWIW, I changed it the way I did because _F
202 _openFuture.then<File>((openedFile) => openedFile.close());
203 } 202 }
204 203
205 // Class for encapsulating the native implementation of files. 204 // Class for encapsulating the native implementation of files.
206 class _File extends FileSystemEntity implements File { 205 class _File extends FileSystemEntity implements File {
207 final String path; 206 final String path;
208 207
209 // Constructor for file. 208 // Constructor for file.
210 _File(this.path) { 209 _File(this.path) {
211 if (path is! String) { 210 if (path is! String) {
212 throw new ArgumentError('${Error.safeToString(path)} ' 211 throw new ArgumentError('${Error.safeToString(path)} '
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 _tryDecode(readAsBytesSync(), encoding); 547 _tryDecode(readAsBytesSync(), encoding);
549 548
550 Future<List<String>> readAsLines({Encoding encoding: UTF8}) => 549 Future<List<String>> readAsLines({Encoding encoding: UTF8}) =>
551 readAsString(encoding: encoding).then(const LineSplitter().convert); 550 readAsString(encoding: encoding).then(const LineSplitter().convert);
552 551
553 List<String> readAsLinesSync({Encoding encoding: UTF8}) => 552 List<String> readAsLinesSync({Encoding encoding: UTF8}) =>
554 const LineSplitter().convert(readAsStringSync(encoding: encoding)); 553 const LineSplitter().convert(readAsStringSync(encoding: encoding));
555 554
556 Future<File> writeAsBytes(List<int> bytes, 555 Future<File> writeAsBytes(List<int> bytes,
557 {FileMode mode: FileMode.WRITE, bool flush: false}) { 556 {FileMode mode: FileMode.WRITE, bool flush: false}) {
558 return open(mode: mode).then((file) { 557 return open(mode: mode).then((file) async {
floitsch 2017/04/27 22:10:25 The core libraries currently do not use 'async'. I
Bob Nystrom 2017/04/28 00:13:07 Took your change instead. I could have sworn I tri
559 return file.writeFrom(bytes, 0, bytes.length).then((_) { 558 try {
560 if (flush) return file.flush().then((_) => this); 559 await file.writeFrom(bytes, 0, bytes.length);
561 return this; 560 if (flush) await file.flush();
562 }).whenComplete(file.close); 561 return this as File;
562 } finally {
563 await file.close();
564 }
563 }); 565 });
564 } 566 }
565 567
566 void writeAsBytesSync(List<int> bytes, 568 void writeAsBytesSync(List<int> bytes,
567 {FileMode mode: FileMode.WRITE, bool flush: false}) { 569 {FileMode mode: FileMode.WRITE, bool flush: false}) {
568 RandomAccessFile opened = openSync(mode: mode); 570 RandomAccessFile opened = openSync(mode: mode);
569 try { 571 try {
570 opened.writeFromSync(bytes, 0, bytes.length); 572 opened.writeFromSync(bytes, 0, bytes.length);
571 if (flush) opened.flushSync(); 573 if (flush) opened.flushSync();
572 } finally { 574 } finally {
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 void _checkAvailable() { 1066 void _checkAvailable() {
1065 if (_asyncDispatched) { 1067 if (_asyncDispatched) {
1066 throw new FileSystemException( 1068 throw new FileSystemException(
1067 "An async operation is currently pending", path); 1069 "An async operation is currently pending", path);
1068 } 1070 }
1069 if (closed) { 1071 if (closed) {
1070 throw new FileSystemException("File closed", path); 1072 throw new FileSystemException("File closed", path);
1071 } 1073 }
1072 } 1074 }
1073 } 1075 }
OLDNEW
« no previous file with comments | « sdk/lib/core/string.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698