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

Unified Diff: sdk/lib/io/file_impl.dart

Issue 251583004: Clean up readAsLines*. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/file_impl.dart
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
index 1920c37f0c63ae4d7dd7c62b6686480e29602265..5b4cddb0bd2b3f3490e00372834ba0ce5cb43581 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -494,37 +494,14 @@ class _File extends FileSystemEntity implements File {
Future<String> readAsString({Encoding encoding: UTF8}) =>
readAsBytes().then((bytes) => _tryDecode(bytes, encoding));
- String readAsStringSync({Encoding encoding: UTF8}) {
- List<int> bytes = readAsBytesSync();
- return _tryDecode(bytes, encoding);
- }
-
- List<String> _decodeLines(List<int> bytes, Encoding encoding) {
- if (bytes.length == 0) return [];
- var list = [];
- var controller = new StreamController(sync: true);
- var error = null;
- controller.stream
- .transform(encoding.decoder)
- .transform(new LineSplitter())
- .listen((line) => list.add(line), onError: (e) => error = e);
- controller.add(bytes);
- controller.close();
- if (error != null) {
- throw new FileSystemException(
- "Failed to decode data using encoding '${encoding.name}'", path);
- }
- return list;
- }
+ String readAsStringSync({Encoding encoding: UTF8}) =>
+ _tryDecode(readAsBytesSync(), encoding);
- Future<List<String>> readAsLines({Encoding encoding: UTF8}) {
- return readAsBytes().then((bytes) {
- return _decodeLines(bytes, encoding);
- });
- }
+ Future<List<String>> readAsLines({Encoding encoding: UTF8}) =>
+ readAsString(encoding: encoding).then(const LineSplitter().convert);
List<String> readAsLinesSync({Encoding encoding: UTF8}) =>
- _decodeLines(readAsBytesSync(), encoding);
+ const LineSplitter().convert(readAsStringSync(encoding: encoding));
Future<File> writeAsBytes(List<int> bytes,
{FileMode mode: FileMode.WRITE,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698