readAll method
Returns a Stream with the contents of the file as Strings.
Implementation
Stream<String> readAll() {
final controller = StreamController<String>();
final inputStream = _file.openRead();
final stackTrace = StackTraceImpl();
Object? exception;
utf8.decoder.bind(inputStream).transform(const LineSplitter()).listen(
(line) async {
controller.add(line);
},
cancelOnError: true,
//ignore: avoid_types_on_closure_parameters
onError: (Object error) {
exception = error;
unawaited(controller.close());
},
onDone: controller.close,
);
if (exception != null) {
if (exception is DCliException) {
// not an exception, the user just doesn't want to continue.
} else {
throw DCliException.from(exception, stackTrace);
}
}
return controller.stream;
}